<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Calm Engineering</title>
    <link>https://lukastymo.com/</link>
    <description>Recent content on Calm Engineering</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 22 Oct 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://lukastymo.com/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Software Developers Have Become Researchers</title>
      <link>https://lukastymo.com/posts/036-developer-to-researcher/</link>
      <pubDate>Thu, 22 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/036-developer-to-researcher/</guid>
      <description>&lt;p&gt;Software developers have become researchers. We now hand most of the coding to LLMs, so the job has moved to what&#xA;happens before and after the code. Predicting anything in tech is a poor bet. But I have used these tools hands-on since&#xA;the start of the AI wave, and my working day has shifted.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Software developers have become researchers. We now hand most of the coding to LLMs, so the job has moved to what&#xA;happens before and after the code. Predicting anything in tech is a poor bet. But I have used these tools hands-on since&#xA;the start of the AI wave, and my working day has shifted.&lt;/p&gt;&#xA;&lt;p&gt;The old question was: &amp;ldquo;Can you build this and own it?&amp;rdquo; The new one is: &amp;ldquo;Can you find out how to build this, and&#xA;oversee the build?&amp;rdquo;&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;what-the-work-looks-like-now&#34;&gt;What the work looks like now&lt;/h2&gt;&#xA;&lt;p&gt;There is more context to prepare. An LLM predicts the next token from what you give it. The closer that input is to&#xA;the problem, the closer the output lands to the right solution.&lt;/p&gt;&#xA;&lt;p&gt;There are more tasks. Gathering context is research, and research breaks into many small jobs: things to do, things to&#xA;review, things to check. I keep them as a checklist, on paper or on screen.&lt;/p&gt;&#xA;&lt;p&gt;There is more information to manage. LLMs produce a lot of text, much of it boilerplate. Add diagrams, bullet lists&#xA;and other documents, and you need all of them close at hand for the next iteration. Being organised matters more than&#xA;it used to.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-i-research-a-task&#34;&gt;How I research a task&lt;/h2&gt;&#xA;&lt;p&gt;I borrow an idea from Terraform and declarative programming: state what you want, not how to get there.&lt;/p&gt;&#xA;&lt;p&gt;I start every task with 15 minutes away from the LLM. It works like a warm-up at the gym. I write down a list of&#xA;questions, and these become my guiding questions. When the model drifts towards something interesting but useless, I&#xA;check the conversation against them to see whether we are still heading for a solution.&lt;/p&gt;&#xA;&lt;p&gt;I keep at least one markdown note per task, story, feature or epic. It collects everything in one place. The habit was&#xA;useful before LLMs. Now it is essential.&lt;/p&gt;&#xA;&lt;p&gt;My mental model of an LLM is a tree. The model starts at the root and climbs down towards your problem. Good context&#xA;takes it to the right branch, close to the true solution. Useless context, such as &amp;ldquo;My team wants me to solve this&#xA;problem&amp;rdquo;, sends it to the wrong branch. You get &amp;ldquo;Here is a reply you could send: Subject: …&amp;rdquo;, which costs tokens, time&#xA;and quality. Give it just enough of the context that matters.&lt;/p&gt;&#xA;&#xA;&lt;figure class=&#34;figure-wide&#34;&gt;&#xA;  &lt;img &#xA;    src=&#34;https://lukastymo.com/images/posts/036/tree.png&#34; &#xA;    alt=&#34;Diagram: from what the model knows, vague context leads down to office chatter, an email reply template or generic advice; requirements and domain terms lead to your domain and close to the true solution.&#34;&#xA;    class=&#34;w-full h-auto rounded-xl&#34;&#xA;  /&gt;&#xA;  &#xA;    &lt;figcaption class=&#34;mt-3 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;&#xA;      Context decides which branch the model lands on.&#xA;    &lt;/figcaption&gt;&#xA;  &#xA;&lt;/figure&gt;&#xA;&#xA;&#xA;&lt;p&gt;To reach the right branch, I quiz the model first: &amp;ldquo;Do you know how to do X?&amp;rdquo;, &amp;ldquo;Do you know how many places do this?&amp;rdquo;&#xA;That warms up the context before I paste the requirements. Easy tickets are the exception. When I already know the&#xA;answer, I paste the problem straight in, because I can review the output against the solution in my head.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;will-ai-replace-software-developers&#34;&gt;Will AI replace software developers?&lt;/h2&gt;&#xA;&lt;p&gt;Wrong question. The role has moved towards research, and research cannot be automated yet. It is the first step, before&#xA;any agentic pipeline runs. It goes well beyond code review. It needs an understanding of how neural networks work and&#xA;how to use them well. It also needs knowledge management: get the facts from subject matter experts and write them down,&#xA;or, if they already exist, bring them into the context.&lt;/p&gt;&#xA;&lt;p&gt;Without that knowledge, an LLM is a project generator. And if you don&amp;rsquo;t know what you expect, you can&amp;rsquo;t tell when the&#xA;model is wrong. It will explain its output in fluent, confident prose either way.&lt;/p&gt;&#xA;&lt;p&gt;The developer&amp;rsquo;s job is now research: gathering context, asking the right questions and judging the output. An LLM&#xA;cannot do that part for us yet.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>6 AI Practices Every Knowledge Worker Should Steal</title>
      <link>https://lukastymo.com/posts/035-ai-practices/</link>
      <pubDate>Fri, 04 Sep 2026 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/035-ai-practices/</guid>
      <description>&lt;p&gt;Senior developers have spent a lot of time figuring out, the hard way, how to work well with AI. Most of that learning&#xA;has nothing to do with code. It&amp;rsquo;s about how any knowledge worker should think before handing a task to a model. Here are&#xA;six of those practices, translated for marketers, writers, and anyone else who delegates work to AI.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Senior developers have spent a lot of time figuring out, the hard way, how to work well with AI. Most of that learning&#xA;has nothing to do with code. It&amp;rsquo;s about how any knowledge worker should think before handing a task to a model. Here are&#xA;six of those practices, translated for marketers, writers, and anyone else who delegates work to AI.&lt;/p&gt;&#xA;&lt;p&gt;Don&amp;rsquo;t always use all of them. Learn them, then cherry-pick whichever one fits the task in front of you.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;lingo&#34;&gt;Lingo&lt;/h2&gt;&#xA;&lt;p&gt;Before we jump in, since this post is written for a wide audience, let&amp;rsquo;s agree on the meaning of a few terms used below.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;LLM / Model&lt;/strong&gt; - LLM and Model mean the same thing here: Large Language Models, trained at real cost in power-intensive&#xA;labs. That cost is exactly what makes them capable of tasks a human would otherwise do.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Agent and Agentic workflow&lt;/strong&gt; - Chat means you send a prompt and get a reply. An Agent goes further: it can run&#xA;commands, edit files, and search the web. It doesn&amp;rsquo;t just answer, it acts. Give it a goal and let it run on its own, and&#xA;that&amp;rsquo;s an agentic workflow.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt; - everything the model sees in one request: your prompt, the conversation so far, and any files you feed in.&#xA;It has a fixed size limit, once full, older content gets dropped to make room. Nothing carries into a new session unless&#xA;something, like a memory file, re-adds it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Session&lt;/strong&gt; - one continuous conversation with its own context, independent of other chats. Nothing carries from one&#xA;session to the next unless you bring it yourself: a memory file, a pasted summary, a re-stated spec.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;1-build-fundamentals-and-understanding-first&#34;&gt;1. Build fundamentals and understanding first&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1762146828422-50a8bd416d3c&#34; alt=&#34;Architectural blueprints spread out on a surface&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;The shift is clear: we&amp;rsquo;re moving from doing the labor ourselves to overseeing it. To oversee something, you really have&#xA;to know what you&amp;rsquo;re building. You need the fundamentals in whatever you do. If you have them, the model works as a force&#xA;multiplier: delegation goes smoothly, and any gaps in the spec that get filled with nonsense or hallucination are less&#xA;costly, because you catch them early.&lt;/p&gt;&#xA;&lt;p&gt;Eroding fundamentals works against you. The model will sound smart and convince you, every time, to go in the wrong&#xA;direction.&lt;/p&gt;&#xA;&lt;p&gt;Equally important: before you ask the model to do anything, sketch your own guess of what the answer should look like.&#xA;Drawing a diagram on paper is a good starting point. Then compare it to what the model actually produces: for a&#xA;programming task, ask it for a sequence diagram of how the code works right now; for a marketing task, ask it to map out&#xA;how your email campaign works today. The gap between your sketch and its diagram is exactly where your understanding is&#xA;thin, and now you know where to focus.&lt;/p&gt;&#xA;&lt;p&gt;This is the most important step. It has given me a lot of benefit in the past, and caused a lot of problems whenever I&#xA;ignored it. Every practice below depends on it. Because it matters so much, I start every task from an empty note with&#xA;the same recurring sections: &amp;ldquo;How it works right now,&amp;rdquo; &amp;ldquo;Architecture,&amp;rdquo; &amp;ldquo;Goals,&amp;rdquo; &amp;ldquo;What I need to learn.&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;A marketer who always starts from an AI-drafted campaign never builds the instinct for what a good campaign structure&#xA;looks like. They lose the ability to catch a subtly wrong offer or an off-brand tone, and that instinct is exactly what&#xA;their oversight role depends on. We&amp;rsquo;re overseeing the model every single day, so it&amp;rsquo;s a core responsibility, not a&#xA;one-off check.&lt;/p&gt;&#xA;&lt;p&gt;For the same reason, a developer who never writes code loses the ability to spot a subtly wrong abstraction, an&#xA;overcomplicated decision, or a silly fallback that makes the code more expensive to run, harder to maintain long-term,&#xA;and more error-prone.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;2-spec-driven-work&#34;&gt;2. Spec driven work&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1767190041030-f2f3a6654c5e&#34; alt=&#34;Notebook and pen next to a keyboard on a desk&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;Once you trust your own understanding, the next step is putting it into words the model can act on. Before an&#xA;interaction with an LLM or Agent, especially when the task is complex or multi-step, it&amp;rsquo;s a healthy habit to write down&#xA;what you actually aim for.&lt;/p&gt;&#xA;&lt;p&gt;In a software development context, here&amp;rsquo;s a small example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Split view&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## GOAL&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;I see a unified view of my strong deadlines (tasks with due dates), &lt;span class=&#34;gs&#34;&gt;**together with**&lt;/span&gt; softer notes with bullets or&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;checkboxes which are adequate for the chosen day&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## CONSTRAINTS&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Relevant things for a day in terms of notes, maybe current week, current month, current year (stacked view)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Must look good on mobile&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; We must not reinvent the wheel&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## AC&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; No tasks, today note&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Today tasks, no today note or anything else&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Today tasks + today note&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Today tasks + today note + this week note + this month + this quarter + this year note&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; All of them on mobile, small screen&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It can be easily translated to other professions. Let&amp;rsquo;s take marketing:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# q3-customer-win-back-email.md&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## Goal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Draft a win-back email campaign for customers who churned in the last 90 days.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## Constraints&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Must use existing brand voice guide (see &lt;span class=&#34;sb&#34;&gt;`brand/tone-guide.md`&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Offer: 20% discount, valid 14 days, no other discount structures&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Must reference GDPR-compliant unsubscribe language (see &lt;span class=&#34;sb&#34;&gt;`legal/email-footer.md`&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Max 150 words body copy, one clear CTA&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Do not reference competitor names or pricing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## Acceptance criteria&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Subject line A/B variants (2), each under 50 characters&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Body copy passes brand tone check (no exclamation-heavy, no &amp;#34;hey there!&amp;#34;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; CTA links to /reactivate landing page, not homepage&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Includes required legal footer verbatim&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are several reasons behind this technique. We often don&amp;rsquo;t know exactly what we want. We leave gaps. When we&#xA;delegate to a human, that&amp;rsquo;s not a big deal, because a human will follow up and ask. In the AI world, leaving gaps means&#xA;the agent guesses and fills them itself, which can be a terrible choice.&lt;/p&gt;&#xA;&lt;p&gt;Without a spec, you only spot that something&amp;rsquo;s off once the agent finishes. That means more back-and-forth, and some&#xA;frustration.&lt;/p&gt;&#xA;&lt;p&gt;Writing the spec also gives you a broader view of things you never thought about before, which can itself trigger&#xA;improvements to what you&amp;rsquo;re building.&lt;/p&gt;&#xA;&lt;p&gt;The path from spec to execution gets standardized too. Over time, a good spec and a bad spec become obvious. Other&#xA;people on the team can learn from them, learn how to write their own. If something didn&amp;rsquo;t work well, you can always go&#xA;back to the spec and improve it for next time.&lt;/p&gt;&#xA;&lt;p&gt;And that&amp;rsquo;s exactly where you get differentiation. Different people using the same tool can produce wildly different&#xA;results, because more experienced people know what to specify and what not to leave for the model to guess. A strong&#xA;spec turns the model into a real force multiplier. A weak one just makes a mediocre brief sound smarter while staying&#xA;useless.&lt;/p&gt;&#xA;&lt;p&gt;A lot of the AI slop out there comes from a mediocre &amp;ldquo;we just need to use AI and push it to users&amp;rdquo; attitude, with no&#xA;UI/UX or user thinking behind it. It all comes down to a broken spec, or no spec at all.&lt;/p&gt;&#xA;&lt;p&gt;Personally, I&amp;rsquo;ve always regretted skipping the spec on a complex feature. The things that came up as I went could have&#xA;been thought through beforehand, saving me a lot of time and frustration.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;3-context-engineering&#34;&gt;3. Context engineering&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1664526937033-fe2c11f1be25&#34; alt=&#34;Abstract diagram of connected nodes and lines&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;A good spec tells the model what to build. Context tells it how to think about the problem. Before delegating, it&amp;rsquo;s&#xA;often a good idea to warm up the agent. Picture an infinitely long knowledge tree with lots of branches to different&#xA;concepts. By asking questions or giving instructions first, you climb toward the cluster of expert knowledge you need to&#xA;complete the task.&lt;/p&gt;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;read spec/sqs-retry-backoff.md, common/retry/RetryPolicy.scala, and SqsConsumer.scala. Don&amp;#39;t touch anything else yet -&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;summarise the integration points you&amp;#39;d touch.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or, in the marketing context:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Read spec/q3-customer-win-back-email.md, brand/tone-guide.md, and the last two win-back campaigns in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;campaigns/2026-q1-winback.md and campaigns/2025-q4-winback.md. Don&amp;#39;t draft anything yet, summarise the tone patterns and&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;offer structures you&amp;#39;d follow, and flag anything in the spec that conflicts with what worked before.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Just like with spec-driven work, gaps get filled in silently by the model. Here, the gaps are about how the model&#xA;reasons through, or thinks about, the problem.&lt;/p&gt;&#xA;&lt;p&gt;Without curation, the model guesses which parts of a document matter. The key difference comes from cherry-picking the&#xA;highest-signal information and feeding only that to the model.&lt;/p&gt;&#xA;&lt;p&gt;Reading and summarizing is bread and butter for what models do best. It&amp;rsquo;s a cheap step that gives a lot of benefit&#xA;before the expensive one.&lt;/p&gt;&#xA;&lt;p&gt;Context sets boundaries. If you don&amp;rsquo;t specify them here, you just push the problem to a later stage, where it takes more&#xA;time to fix, because the model can already have &amp;ldquo;turned&amp;rdquo; toward the wrong assumption.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;4-delegation-over-autocomplete&#34;&gt;4. Delegation over autocomplete&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1761225291317-6bbf383011f2&#34; alt=&#34;Runner passing a relay baton to a teammate&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;With a spec and context in place, you can finally hand over real work instead of babysitting autocomplete. Current&#xA;models can chain more tool calls in a row without derailing than they used to, which is what makes multi-step, automated&#xA;work realistic now, not just a longer chat reply. That doesn&amp;rsquo;t mean you switch off, though. The more freedom you give&#xA;the agent, the more oversight the outcome needs, especially while you and the model are still figuring out what &amp;ldquo;done&amp;rdquo;&#xA;looks like for this specific task.&lt;/p&gt;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;fix BUG-123 per AGENTS.md bug-fix workflow:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;write a failing test that reproduces it, implement the fix, run the full test suite, create branch fix/BUG-123 locally.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Don&amp;#39;t push. Report back once green, or sooner if you hit something that needs a judgment call.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or a non-dev example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Draft the win-back campaign per spec/q3-customer-win-back-email.md and marketing/AGENTS.md: two subject line variants,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;body copy, checked against the brand tone guide and required legal footer. Save as a draft in the shared folder. Don&amp;#39;t&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;send. Flag anything that doesn&amp;#39;t meet the acceptance criteria before I look at it.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Models are good at following multi-step instructions. This step should come after you&amp;rsquo;ve defined the spec and the&#xA;context, because you&amp;rsquo;re giving the model a lot of freedom here. Curation happens at this stage: filtering and&#xA;reformatting the output.&lt;/p&gt;&#xA;&lt;p&gt;The reasoning behind this practice is that you&amp;rsquo;re the most expensive resource. Stop switching context, and stop being&#xA;the bottleneck.&lt;/p&gt;&#xA;&lt;p&gt;Just like in code, you can build in iteration: specify KPIs for the task, let the model try a few approaches, run them&#xA;against your criteria, and only report back once it finds a winner. This forces the model to check its own output, which&#xA;is always a good idea, because it learns from that feedback where the right solution is.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Try three different subject line styles for the win-back email: urgency, curiosity, and plain benefit-led.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Score each against the brand tone guide and predicted open rate. Only show me the highest-scoring one,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;with your reasoning for why it beat the other two.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h2 id=&#34;5-multi-agent-orchestration&#34;&gt;5. Multi-agent orchestration&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1772114037582-633fe892763a&#34; alt=&#34;Desk with multiple computer monitors running in parallel&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;Once delegation feels safe on one task, the next step is running several at once. You can also do work in parallel, as&#xA;long as it can be split into independent pieces.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Agent 1: worktree A&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;review spec/sqs-retry-backoff.md PR against acceptance criteria, flag anything missed&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Agent 2: worktree B&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;add CloudWatch alarm for DLQ depth &amp;gt; 0 to terraform/cdp-ingestion, follow existing alarm module pattern&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Agent 3: worktree C&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;investigate flaky test KafkaConsumerSpec.scala line 84, find root cause, don&amp;#39;t fix yet, report back&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And a non-dev example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Task A: campaign review&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;review the win-back email draft against spec/q3-customer-win-back-email.md acceptance criteria, flag anything missed.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Don&amp;#39;t send.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Task B: new content, context-first (same fix as Thursday&amp;#39;s Agent 2)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;read hr/careers-page-style-guide.md and two recent job posts in postings/2026-*.md. Summarise tone and structure&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;conventions before drafting anything.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gh&#34;&gt;# Task C: investigate, don&amp;#39;t fix&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;look into why the Q2 churn number in last week&amp;#39;s board deck doesn&amp;#39;t match this week&amp;#39;s dashboard. Find the discrepancy,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;don&amp;#39;t correct either document yet. Report back.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As long as the tasks are independent, there&amp;rsquo;s no reason to run them one after another. In an agentic workflow, the human&#xA;is the bottleneck. Multi-agent orchestration pushes that bottleneck as far downstream as possible. This is especially&#xA;useful when the tasks are mundane, boring, and simple to verify.&lt;/p&gt;&#xA;&lt;p&gt;There is a limit to this practice. If your tasks aren&amp;rsquo;t independent, or they&amp;rsquo;re involved and need multiple iterations,&#xA;it&amp;rsquo;s much better to focus on one and do it well than to jump back and forth.&lt;/p&gt;&#xA;&lt;p&gt;Another place this method shines: tag tasks as candidates the moment you spot them, a &lt;code&gt;#parallel-ok&lt;/code&gt; label in your task&#xA;tracker, a comment on the ticket, whatever you already use, so you don&amp;rsquo;t have to re-scan the whole backlog every time&#xA;you have a few idle agents.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;6-project-memory-files&#34;&gt;6. Project memory files&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1569235186275-626cb53b83ce&#34; alt=&#34;Filing cabinet drawer with folders&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;All of this repeats across sessions, unless you find a way to make it stick. Models don&amp;rsquo;t have memory. They behave like&#xA;they do only because they store some things in files from time to time. If you work in the filesystem in an agentic&#xA;workflow, a common practice is to create an AGENTS.md or CLAUDE.md file. The agent reads this file at session start, or&#xA;whenever it&amp;rsquo;s referenced, and treats it as high-priority context. The expected filename differs depending on which model&#xA;you use.&lt;/p&gt;&#xA;&lt;p&gt;For software development, this file can hold conventions, gotchas, and standards your company follows.&lt;/p&gt;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## Gotchas&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; SqsConsumer retries: use RetryPolicy typeclass, never Thread.sleep (breaks IO referential transparency, caught in&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  review 2026-09)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Terraform alarm modules: always check &lt;span class=&#34;sb&#34;&gt;`terraform/modules/alarms/README.md`&lt;/span&gt; before adding new alarm blocks, naming&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  convention matters for dashboards&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; KafkaConsumerSpec flakiness: root cause was test ordering dependency, not the consumer itself, see PR &lt;span class=&#34;ni&#34;&gt;#412&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And for a non-dev example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;gu&#34;&gt;## Gotchas&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Win-back campaigns: always check campaigns/2026-q1-winback.md for the discount used last cycle before proposing a new&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  one, legal flagged offers above 20% in Q1, caught in review 2026-03&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Job postings: always check hr/pay-band-language.md before drafting compensation ranges, generic phrasing like&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &amp;#34;competitive salary&amp;#34; gets rejected by compliance, use the exact pay-band template instead&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;-&lt;/span&gt; Q2 board deck churn discrepancy: root cause was two teams pulling from different dashboards (Salesforce vs. product&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  analytics), not a calculation error, see thread in &lt;span class=&#34;ni&#34;&gt;#finance&lt;/span&gt;-reporting 2026-06&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, this helps other people on the team too. It speeds up all the previous steps, because you&amp;rsquo;re teaching&#xA;the model how to navigate your knowledge graph for a particular type of task.&lt;/p&gt;&#xA;&lt;p&gt;None of these six practices work in isolation. Fundamentals are what let you judge whether the output is any good in the&#xA;first place. Everything else, the spec, the context, the delegation, only pays off once you can tell a good result from&#xA;a confident-sounding bad one.&lt;/p&gt;&#xA;&lt;p&gt;These habits started with software engineers, but they apply to any work you do with AI.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>What do I keep on the top monitor from my 3-monitors setup</title>
      <link>https://lukastymo.com/posts/034-what-do-i-keep-on-the-top-monitor/</link>
      <pubDate>Thu, 16 Jul 2026 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/034-what-do-i-keep-on-the-top-monitor/</guid>
      <description>&lt;div class=&#34;not-prose my-6 text-sm leading-relaxed text-gray-600 dark:text-gray-400&#34;&gt;&#xA;  &lt;span class=&#34;font-bold text-gray-900 dark:text-gray-100&#34;&gt;Summary.&lt;/span&gt; My Daily Note is one page, driven by the calendar, giving me a unified view. Every day it shows only what is&#xA;relevant to that period: today, this week, this month, this quarter, nothing more, nothing less.&lt;/div&gt;&#xA;&#xA;&lt;p&gt;I run three monitors, and I am picky about what gets a spot on any of them. The top one is reserved for a single&#xA;tab: my Daily Note.&lt;/p&gt;</description>
      <content:encoded>&#xA;&#xA;&lt;div class=&#34;not-prose my-6 text-sm leading-relaxed text-gray-600 dark:text-gray-400&#34;&gt;&#xA;  &lt;span class=&#34;font-bold text-gray-900 dark:text-gray-100&#34;&gt;Summary.&lt;/span&gt; My Daily Note is one page, driven by the calendar, giving me a unified view. Every day it shows only what is&#xA;relevant to that period: today, this week, this month, this quarter, nothing more, nothing less.&lt;/div&gt;&#xA;&#xA;&lt;p&gt;I run three monitors, and I am picky about what gets a spot on any of them. The top one is reserved for a single&#xA;tab: my Daily Note.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-amber-400 bg-amber-50 dark:border-amber-500 dark:bg-amber-950 text-amber-900 dark:text-amber-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ⚠️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Disclosure&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;I&amp;rsquo;m the founder of &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:034-what-do-i-keep-on-the-top-monitor&#34;&gt;3Monads&lt;/a&gt;,&#xA;a Life Management app mentioned throughout this post. The Daily Note feature I describe below works with any tool&#xA;that gives you a fresh note each day. I used Roam Research for years before building my own.&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;Back when I used Roam Research, I liked seeing a new, clean daily note every day. It let me plan my day.&lt;/p&gt;&#xA;&lt;p&gt;That was not enough, though. Sometimes I wanted to plan my week, month, or year, to keep a few things in view over&#xA;a longer period.&lt;/p&gt;&#xA;&lt;p&gt;At the same time, I was building 3Monads, a life management app. I quickly realized I could add this feature there,&#xA;and I have used it every day since.&lt;/p&gt;&#xA;&lt;p&gt;I recommend this to fellow software engineers and to anyone else with a lot going on, &lt;strong&gt;who wants to release the&#xA;cognitive load of remembering &amp;ldquo;what was I actually doing this week?&amp;rdquo;&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;My Daily Note now sits inside 3Monads, split into a few sections stacked on top of each other. It starts small:&#xA;just today&amp;rsquo;s note. Under the hood it is a date-based filter: anything I write on a future week, month, or quarter&#xA;page stays parked there until that period starts, then its section floats up and stacks above today, and drops off&#xA;once the period ends. I use three sections, but I could add more.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The Monthly section tells me what I need to learn or finish reading this month.&lt;/strong&gt; Right now that is finishing &amp;ldquo;Deep&#xA;Learning in Python&amp;rdquo;; this quarter it is reaching a Codeforces red rank. I keep adding items there as I go. If&#xA;something takes longer, I move it to the quarterly or yearly section. These items are not as strict as tasks with&#xA;deadlines, but they are still checkable, and they float as reminders. That lets me focus on doing things and come&#xA;back later to whatever I postponed.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/034/4-even-bigger-with-Q3.png&#34; alt=&#34;Quarterly, monthly, and weekly sections stacked above today&#39;s daily note&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Quarterly and monthly items sit above the week and today, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:034-what-do-i-keep-on-the-top-monitor&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;The next section is Week, where I keep my weekly items.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/034/3-plan-today-with-week-plan.png&#34; alt=&#34;Weekly section above today&#39;s daily note&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My weekly section sits right above today, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:034-what-do-i-keep-on-the-top-monitor&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;The last section is the daily one, new every day. I like to start at 6:50 with coffee and list checkboxes for&#xA;things to do. I use indentation for different areas, like Work or Side Projects.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/034/2-plan-today.png&#34; alt=&#34;Today&#39;s daily note with nested checkboxes for Work and Blog post&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Today&#39;s note, with indented checkboxes for different areas, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:034-what-do-i-keep-on-the-top-monitor&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;I think this works well because it leaves it up to the user to decide when things should disappear from focus.&#xA;&lt;strong&gt;A lot of things in our lives do not need to become tasks. If we turn everything into a task, we end up with long&#xA;backlogs and never accomplish much,&lt;/strong&gt; which hurts our creativity and self-development. Try it today, and see how&#xA;much easier it gets to remember things.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;why-not-just-use-a-separate-note-or-paper&#34;&gt;Why not just use a separate note, or paper?&lt;/h2&gt;&#xA;&lt;p&gt;A separate note works fine too, but you have to remember to move things out of sight yourself. I have done this&#xA;before: a monthly goal sat untouched in a random note for close to three months before I noticed it again. When the&#xA;month ends and you still have a few goals left, nothing does that cleanup for you. You either carry them over&#xA;manually or they quietly rot in a note you stop opening.&lt;/p&gt;&#xA;&lt;p&gt;Paper has the same problem, plus one more. It is great for initial thinking and quick scratch notes, and I still&#xA;write physical daily notes from time to time. But paper does not last and does not travel well. When I want to keep&#xA;something, I move it into 3Monads so I can reach it from any device.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-to&#34;&gt;How to&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to &lt;a href=&#34;https://3monads.com/&#34;&gt;3monads.com&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Sign up, or sign in if you already have an account.&lt;/li&gt;&#xA;&lt;li&gt;Click Daily Note in the left sidebar.&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You will see a blank day. Plan your day.&lt;/li&gt;&#xA;&lt;li&gt;Do you need to remember something further out? Find it in the calendar on top and click &lt;code&gt;W&amp;lt;number&amp;gt;&lt;/code&gt; for a&#xA;week, or use the left arrow to step out to a month or quarter. Write it there, and it stays parked until&#xA;that period starts, then stacks above today automatically.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;The rest is standard markdown: Ctrl+Enter turns a line into a bullet, press again for a checkbox, again to&#xA;toggle it, &lt;code&gt;#&lt;/code&gt; for headers, Ctrl+H/B/I for highlight, bold, italic, and Tab/Shift+Tab to indent.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Set this up once, and the top monitor stops being just another screen. It becomes the one place you glance at to&#xA;know what actually needs your attention today.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Human in the Loop</title>
      <link>https://lukastymo.com/posts/033-human-in-the-loop/</link>
      <pubDate>Thu, 09 Jul 2026 12:27:00 +0100</pubDate>
      <guid>https://lukastymo.com/posts/033-human-in-the-loop/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1680783954745-3249be59e527&#34; alt=&#34;Robot and human hands reaching toward each other&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;AI won&amp;rsquo;t deliver the productivity gains everyone expects, because models still aren&amp;rsquo;t good enough at complex tasks.&#xA;They need constant nudging, small pushes only a human can give. No prompt, no markdown file, no agent loop can&#xA;reliably deliver value for a business on its own. It works on side projects. Prototyping gets faster. Every now and&#xA;then, a couple of iterations even ship a feature without much help. But once real complexity shows up, a human has&#xA;to step in.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1680783954745-3249be59e527&#34; alt=&#34;Robot and human hands reaching toward each other&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;AI won&amp;rsquo;t deliver the productivity gains everyone expects, because models still aren&amp;rsquo;t good enough at complex tasks.&#xA;They need constant nudging, small pushes only a human can give. No prompt, no markdown file, no agent loop can&#xA;reliably deliver value for a business on its own. It works on side projects. Prototyping gets faster. Every now and&#xA;then, a couple of iterations even ship a feature without much help. But once real complexity shows up, a human has&#xA;to step in.&lt;/p&gt;&#xA;&lt;p&gt;The problem is that if we let models drive delivery, humans stop learning and understanding what&amp;rsquo;s happening. To&#xA;jump back into the loop, we have to spend the time we saved on generation actually reading the code. Before, this&#xA;happened automatically: we wrote code and understood it as we went. Now we move fast at first, without feeling how a&#xA;retry policy, a timeout, or a cache TTL actually behaves under load. When something breaks, we have to debug and&#xA;read what the model produced in the first place.&lt;/p&gt;&#xA;&lt;p&gt;Companies can&amp;rsquo;t replace their staff with AI if they want to innovate or ship real changes. AI can drive a&#xA;predictable pipeline of tasks on legacy systems, where everything is already known. Renaming a deprecated field&#xA;across a hundred call sites, or creating a simple ETL pipeline, is exactly this kind of work. A human in the loop can&#xA;start the agents there and let them run for long stretches without major interruption. New features and new&#xA;requirements are different: they need real thinking and understanding, at least the moment something breaks.&lt;/p&gt;&#xA;&lt;p&gt;Human in the loop is a good mental model for this. Even though the model produces the code, it does it hand in hand&#xA;with a human, who acts as the memory and the reasoning: the one who tells the automation &amp;ldquo;that&amp;rsquo;s not how it should&#xA;work.&amp;rdquo; Take that human out, and the loop breaks.&lt;/p&gt;&#xA;&lt;p&gt;This is a kind of technical debt. When a model ships something nobody reviewed closely, nobody on the team really&#xA;understands why it works the way it does. When it breaks in production, paying off that debt means&#xA;reverse-engineering code no one remembers writing or reviewing, which costs far more time than reading it upfront&#xA;would have. The longer we let models run on autopilot, the further we drift from the code, and the more that debt&#xA;compounds. Like any other debt, code or financial, the longer we wait, the more it costs.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Using Deferred Execution to Tame AI Agents</title>
      <link>https://lukastymo.com/posts/032-functional-programming-concepts-to-tame-your-ai-agents/</link>
      <pubDate>Mon, 15 Jun 2026 09:00:00 +0100</pubDate>
      <guid>https://lukastymo.com/posts/032-functional-programming-concepts-to-tame-your-ai-agents/</guid>
      <description>&lt;p&gt;Never trust your model with write permissions. You&amp;rsquo;ve probably read the stories: models dropping production databases,&#xA;deleting emails, triggering outages. It happens when you hand too many permissions to your agent, especially write ones.&#xA;It&amp;rsquo;s tempting. It works, until it doesn&amp;rsquo;t.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Never trust your model with write permissions. You&amp;rsquo;ve probably read the stories: models dropping production databases,&#xA;deleting emails, triggering outages. It happens when you hand too many permissions to your agent, especially write ones.&#xA;It&amp;rsquo;s tempting. It works, until it doesn&amp;rsquo;t.&lt;/p&gt;&#xA;&lt;p&gt;My story wasn&amp;rsquo;t catastrophic. But it could have been.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-incident&#34;&gt;The incident&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1743090660977-babf07732432&#34; alt=&#34;Code displayed on a dark screen, syntax highlighted in blue and red&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;I was fixing some Terraform and let Cursor make the changes, planning to review them afterward. Here&amp;rsquo;s what actually&#xA;happened:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The agent made the change I asked for.&lt;/li&gt;&#xA;&lt;li&gt;It raised a PR, bypassing my global rule that explicitly forbade running any git write commands.&lt;/li&gt;&#xA;&lt;li&gt;It merged the PR without waiting for review. It called the GitHub CLI to approve its own PR.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Merging the PR kicked off &lt;code&gt;terraform apply&lt;/code&gt;. I caught it in time, but barely.&lt;/p&gt;&#xA;&lt;p&gt;I confronted the agent afterward. It admitted ignoring both the global rule and the immediate prompt. Deliberately.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-functional-programming-insight&#34;&gt;The functional programming insight&lt;/h2&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve seen this failure mode before. In code, it&amp;rsquo;s called imperative programming: instructions execute one after another,&#xA;and effects happen immediately. Functional programming solves this with deferred execution: describe what should happen,&#xA;compose it all together, run nothing yet. Effects only execute at the very end. Haskell calls this moment the &amp;ldquo;end of&#xA;the world.&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;That&amp;rsquo;s exactly what we need with AI agents.&lt;/p&gt;&#xA;&lt;p&gt;An agent that can execute write operations freely is imperative. Every tool call is a live mutation. An agent that&#xA;describes what it wants to do and waits for a human checkpoint is functional: it defers effects, composes safely, and&#xA;only executes when you explicitly confirm.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;layered-protection-that-actually-works&#34;&gt;Layered protection that actually works&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1658479657379-e0adb7cb91e8&#34; alt=&#34;A computer terminal with a blue-lit screen showing hacker-style interface&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Plan mode.&lt;/strong&gt; Cursor&amp;rsquo;s plan mode is the first gate. The agent reasons and proposes rather than executing. It&amp;rsquo;s excellent,&#xA;but it&amp;rsquo;s a conversational mode, not a technical lock. A follow-up prompt or accidental approval can push the agent past&#xA;it. Plan mode alone isn&amp;rsquo;t enough.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Allowlist run mode.&lt;/strong&gt; Go to Cursor Settings → Agents → Run Mode → Allowlist. Never add destructive commands:&#xA;&lt;code&gt;terraform apply&lt;/code&gt;, or anything that deletes or overwrites files. Better still: leave &lt;code&gt;git&lt;/code&gt; and &lt;code&gt;gh&lt;/code&gt; off the allowlist&#xA;entirely. The agent has to ask you every time it wants to run one. I tried the sandboxed variant but found it too&#xA;limiting: it couldn&amp;rsquo;t &lt;code&gt;cd&lt;/code&gt; into directories outside the workspace. Plain Allowlist, without sandbox, gives the right&#xA;balance.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Branch protection with no self-approval.&lt;/strong&gt; Set main branch protection and disable self-approval for PRs. This is&#xA;mandatory. An agent that can approve its own PR defeats the entire protection model.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;why-global-rules-are-not-enough&#34;&gt;Why global rules are not enough&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://images.unsplash.com/photo-1762242298589-582f5f6c3fb1&#34; alt=&#34;Laptop screen displaying lines of code&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;You might think a global rule would prevent all of this. I had one. Mine looked like this:&lt;/p&gt;&#xA;&lt;pre style=&#34;white-space: pre-wrap; word-break: break-word;&#34;&gt;Never perform any git write operations - no commits, branch creation/deletion/renaming, merges, rebases, resets, or remote pushes of any kind. Read-only git operations (fetch, pull, log, status, diff) are allowed. If a task requires committing or publishing changes, stop and ask the user to do it manually.&lt;/pre&gt;&#xA;&lt;p&gt;It didn&amp;rsquo;t work. Here&amp;rsquo;s why.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Instruction hierarchy.&lt;/strong&gt; Models don&amp;rsquo;t treat all positions in the context window equally. Instructions buried deep in a&#xA;long context are read less reliably. A global rule is a few extra tokens, not a hard constraint. If you must use global&#xA;rules, put the most important constraints at the top of the system prompt, not buried in a long rules file.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;RLHF optimises for task completion, not rule compliance.&lt;/strong&gt; Reinforcement Learning from Human Feedback trains models to&#xA;complete tasks even when instructions are imprecise. This is what makes agents feel intelligent: they fill in gaps and&#xA;push through ambiguity. The same mechanism also means a model will work around a rule if completing the task seems to&#xA;require it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;No persistent constraint mechanism.&lt;/strong&gt; There is no architectural layer in a standard LLM that enforces rules at&#xA;inference time. A rule in the system prompt is a few more tokens in the context. It has no special status. The model&#xA;can, and sometimes will, ignore it.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-practical-conclusion&#34;&gt;The practical conclusion&lt;/h2&gt;&#xA;&lt;p&gt;Treat your AI agents the way you&amp;rsquo;d treat a powerful but impulsive engineer: give them space to work, but build the&#xA;guardrails into the environment, not the conversation.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Separate read and write permissions explicitly.&lt;/li&gt;&#xA;&lt;li&gt;Use Allowlist mode; don&amp;rsquo;t rely on the model&amp;rsquo;s self-restraint.&lt;/li&gt;&#xA;&lt;li&gt;Protect main with branch rules and no self-approval.&lt;/li&gt;&#xA;&lt;li&gt;Use plan mode as a first gate, not the only gate.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Global rules are suggestions. Structural constraints are enforcement. Only the second kind reliably works.&lt;/p&gt;&#xA;&lt;!-- Images used in this post (Rule 3)&#xA;- The incident: https://images.unsplash.com/photo-1743090660977-babf07732432 — search: &#34;code dark screen terminal&#34;&#xA;- Layered protection: https://images.unsplash.com/photo-1658479657379-e0adb7cb91e8 — search: &#34;computer screen blue hacker terminal&#34;&#xA;- Why global rules are not enough: https://images.unsplash.com/photo-1762242298589-582f5f6c3fb1 — search: &#34;laptop code screen&#34;&#xA;--&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Daily notes: the simplest productivity habit I know</title>
      <link>https://lukastymo.com/posts/031-daily-note/</link>
      <pubDate>Mon, 08 Jun 2026 09:00:00 +0100</pubDate>
      <guid>https://lukastymo.com/posts/031-daily-note/</guid>
      <description>&lt;p&gt;Most mornings, I start with one blank note and dump everything that&amp;rsquo;s on my mind. In a few minutes, I feel calmer and&#xA;clearer about what to do next.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;why-unfinished-tasks-stay-on-your-mind&#34;&gt;Why unfinished tasks stay on your mind&lt;/h2&gt;&#xA;&lt;p&gt;In 1920, Bluma Zeigarnik ran a study and found that interrupted tasks are remembered better than completed ones.&#xA;Surprisingly, they occupy human memory even after they&amp;rsquo;re no longer active. We know this as the Zeigarnik&#xA;effect. &lt;a href=&#34;https://en.wikipedia.org/wiki/Zeigarnik_effect&#34;&gt;[1]&lt;/a&gt;&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Most mornings, I start with one blank note and dump everything that&amp;rsquo;s on my mind. In a few minutes, I feel calmer and&#xA;clearer about what to do next.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;why-unfinished-tasks-stay-on-your-mind&#34;&gt;Why unfinished tasks stay on your mind&lt;/h2&gt;&#xA;&lt;p&gt;In 1920, Bluma Zeigarnik ran a study and found that interrupted tasks are remembered better than completed ones.&#xA;Surprisingly, they occupy human memory even after they&amp;rsquo;re no longer active. We know this as the Zeigarnik&#xA;effect. &lt;a href=&#34;https://en.wikipedia.org/wiki/Zeigarnik_effect&#34;&gt;[1]&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Humans, just like computers, use a mechanism called working memory. It has limited capacity but is very fast, allowing&#xA;you to remember someone&amp;rsquo;s name or a few things from the current meeting. There is a simple trick: if you offload what&amp;rsquo;s&#xA;in your working memory onto daily notes during the day, your brain feels relief and your cognitive ability and creativity&#xA;improve as a result. &lt;a href=&#34;https://doi.org/10.1037/a0024192&#34;&gt;[2]&lt;/a&gt; &lt;a href=&#34;https://www.psychologytoday.com/sg/blog/natural-order/202209/how-the-little-known-zeigarnik-effect-impacts-everyone-daily&#34;&gt;[3]&lt;/a&gt;&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/031/02.png&#34; alt=&#34;Over a day, a daily note can expand to quite a bit of things to do&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Over a day, it can expand to quite a bit of things to do, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:031-daily-note&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;what-i-tried-before&#34;&gt;What I tried before&lt;/h2&gt;&#xA;&lt;p&gt;Before I had this system, I did two things that I think a lot of people will recognise. The first was just ignoring it&#xA;and trusting my memory. We all know how that ends: I&amp;rsquo;d remember something when it was already too late, forget about an&#xA;interesting book, or miss a task someone was waiting on.&lt;/p&gt;&#xA;&lt;p&gt;The other thing I tried was adding proper tasks to my to-do app or read-later app. I never got back to them, and the&#xA;list kept growing. One time, I left a simple follow-up in that pile for two weeks before I noticed it again.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;what-belongs-in-a-daily-note&#34;&gt;What belongs in a daily note&lt;/h2&gt;&#xA;&lt;p&gt;That&amp;rsquo;s why daily notes matter. Not just any notes. We don&amp;rsquo;t want to accumulate hundreds of things to do. We only want to&#xA;capture things that are semi-structured: not projects, not formal tasks, but things we need or want to do today or on a&#xA;specific day in the future. (In &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:031-daily-note&#34;&gt;3Monads&lt;/a&gt; you can tap a future date, add a note, and it shows up when that day&#xA;arrives!)&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-to-start-one&#34;&gt;How to start one&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:031-daily-note&#34;&gt;3Monads&lt;/a&gt; (I&amp;rsquo;m the founder, so take the recommendation with that in mind, but any tool that creates a new empty note each day works; I used &lt;a href=&#34;https://roamresearch.com/&#34;&gt;Roam Research&lt;/a&gt; in the past and that works well too, and &lt;a href=&#34;https://obsidian.md/&#34;&gt;Obsidian&lt;/a&gt; with the &lt;a href=&#34;https://help.obsidian.md/plugins/daily-notes&#34;&gt;Daily Notes plugin&lt;/a&gt; is another solid option)&lt;/li&gt;&#xA;&lt;li&gt;Register if you don&amp;rsquo;t have an account, or log in&lt;/li&gt;&#xA;&lt;li&gt;Open Daily Note&lt;/li&gt;&#xA;&lt;li&gt;Write down everything you want to do today&lt;/li&gt;&#xA;&lt;li&gt;Use rich markdown syntax to change bullets into checkboxes (Ctrl+Enter on Windows and ⌘+Enter on Mac)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/031/01.png&#34; alt=&#34;Daily note open in 3Monads&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;A daily note is a simple text note, with markdown if you like, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:031-daily-note&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;how-i-use-mine&#34;&gt;How I use mine&lt;/h2&gt;&#xA;&lt;p&gt;This is one of my favourite productivity and creativity boosts. It&amp;rsquo;s very simple and works even for productivity&#xA;sceptics. Everyone I&amp;rsquo;ve recommended this to has given me positive feedback. I use it in the morning, mainly to prepare&#xA;for standups and to sort out what I need to do at work today, what I plan to learn, and what I plan to do with side&#xA;projects.&lt;/p&gt;&#xA;&lt;p&gt;Roam Research and Obsidian are note-taking systems first. Any escalation from a note to&#xA;something bigger, like a task or a project, requires switching to a different tool. If you want everything in one place,&#xA;&lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:031-daily-note&#34;&gt;3Monads&lt;/a&gt; was built specifically to remove that friction.&lt;/p&gt;&#xA;&lt;p&gt;On top of my daily notes, I have my Execution System in the &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:031-daily-note&#34;&gt;3Monads&lt;/a&gt; app. That means some items are proper tasks I&#xA;keep under specific projects, with due dates, just one click away. I can easily move items between the two: if a bullet&#xA;grows into something that needs repeating, has a future deadline, and will take real time, I promote it to my Execution&#xA;System as a task if it&amp;rsquo;s small, or a project if it&amp;rsquo;s big.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose figure-screenshot&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/031/03.png&#34; alt=&#34;My real, full daily note separated into work, side projects, life, self-dev&#34; class=&#34;h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My real, full daily note separated into work, side projects, life, self-dev, in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:031-daily-note&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;daily-notes-as-a-review-log&#34;&gt;Daily notes as a review log&lt;/h2&gt;&#xA;&lt;p&gt;Daily notes are also great for review. I can look back a few days and see what I was busy with. It&amp;rsquo;s very useful during&#xA;weekly reviews to see where my time went and decide what&amp;rsquo;s still worth doing. (I tend to uncheck and convert items back&#xA;to bullets if I&amp;rsquo;m no longer pursuing them.)&lt;/p&gt;&#xA;&lt;p&gt;I also use it to queue articles and blog posts I want to read on a specific day. Instead of a long read-later list, I&#xA;have a few links for that day. When I come across something interesting and don&amp;rsquo;t have time right now, I add it to that&#xA;day&amp;rsquo;s note. If I still haven&amp;rsquo;t read it, it comes up during my weekly review.&lt;/p&gt;&#xA;&lt;p&gt;This simple habit improves your productivity with almost no cost. Pretty soon you&amp;rsquo;ll feel more relaxed because you&amp;rsquo;ve&#xA;offloaded everything from your brain, and you&amp;rsquo;ll be able to track your progress through the day.&#xA;Because each new day starts with a blank page, you won&amp;rsquo;t be scared by a pile of unfinished tasks. Open a note now and&#xA;write the three most important things you need to do today.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Zeigarnik_effect&#34;&gt;Zeigarnik effect&lt;/a&gt;, Wikipedia&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://doi.org/10.1037/a0024192&#34;&gt;Consider it done! Plan making can eliminate the cognitive effects of unfulfilled goals&lt;/a&gt;. Masicampo &amp;amp; Baumeister, 2011&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.psychologytoday.com/sg/blog/natural-order/202209/how-the-little-known-zeigarnik-effect-impacts-everyone-daily&#34;&gt;How the Zeigarnik effect impacts everyone daily&lt;/a&gt;, Psychology Today&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>How I plan my week in 15 minutes without losing track of anything</title>
      <link>https://lukastymo.com/posts/030-weekly-planning-in-15-min/</link>
      <pubDate>Sat, 23 May 2026 14:00:00 +0100</pubDate>
      <guid>https://lukastymo.com/posts/030-weekly-planning-in-15-min/</guid>
      <description>&lt;p&gt;Weekly planning doesn&amp;rsquo;t need a 2-hour retreat or a Notion template with 47 linked databases.&#xA;Here&amp;rsquo;s what 15 minutes of it looks like in practice.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-amber-400 bg-amber-50 dark:border-amber-500 dark:bg-amber-950 text-amber-900 dark:text-amber-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ⚠️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Disclosure&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;&lt;p&gt;I&amp;rsquo;m the founder of &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;,&#xA;a Project &amp;amp; Tasks Management Platform mentioned throughout this post.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Weekly planning doesn&amp;rsquo;t need a 2-hour retreat or a Notion template with 47 linked databases.&#xA;Here&amp;rsquo;s what 15 minutes of it looks like in practice.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-amber-400 bg-amber-50 dark:border-amber-500 dark:bg-amber-950 text-amber-900 dark:text-amber-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ⚠️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Disclosure&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;&lt;p&gt;I&amp;rsquo;m the founder of &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;,&#xA;a Project &amp;amp; Tasks Management Platform mentioned throughout this post.&lt;/p&gt;&#xA;&lt;p&gt;You can use whatever tool you have. If you don&amp;rsquo;t use any yet, I strongly recommend starting with 3Monads.&#xA;I&amp;rsquo;ve also used Trello, Nozbe, and Todoist in the past. These are decent alternatives with established communities&#xA;and tooling. I wouldn&amp;rsquo;t recommend Notion or other note-taking apps. We need an execution system, not a&#xA;note-taking app.&lt;/p&gt;&#xA;&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;By weekly planning I mean a regular ritual, ideally done every week, where I reflect on the past few days&#xA;and prepare for the week ahead.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;how-do-i-know-its-time-for-weekly-planning&#34;&gt;How do I know it&amp;rsquo;s time for weekly planning?&lt;/h3&gt;&#xA;&lt;p&gt;I have a weekly task set for Sunday that tells me it&amp;rsquo;s time to plan the coming week. I sometimes ignore it&#xA;when I&amp;rsquo;m busy with something else. After a while, I feel like my system has absorbed a lot of new action&#xA;items but I haven&amp;rsquo;t had time to review what actually matters. That&amp;rsquo;s the signal.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/00-weekly-planning-reminder.png&#34; alt=&#34;Weekly planning reminder task set on Sunday&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My weekly regular reminder in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h3 id=&#34;a-few-tips-for-effective-weekly-planning-lessons-learned&#34;&gt;A few tips for effective weekly planning: lessons learned&lt;/h3&gt;&#xA;&lt;p&gt;&lt;strong&gt;Tip 1:&lt;/strong&gt;&#xA;I set a 15-minute timer so I don&amp;rsquo;t drift into unnecessary stuff. Yes, it sometimes takes longer, but the&#xA;clock protects me from procrastination. It signals &amp;ldquo;we&amp;rsquo;re doing planning only today.&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Tip 2:&lt;/strong&gt;&#xA;This one is more of a mindset shift. Life is complex, so things will always surprise your system, whatever&#xA;framework you follow: GTD, PARA, or ad hoc. To stay resilient against the unpredictable, I split my digital&#xA;life into two parts: Execution and Notes.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Execution:&lt;/strong&gt; driven by 3Monads. Anything in that tool is a signal it will get done at some point.&#xA;It&amp;rsquo;s the action system I trust.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Notes:&lt;/strong&gt; a general term for reference material that supports my Execution system: my second brain,&#xA;Zettelkasten, wiki. I use Obsidian with markdown files backed by git.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/01-weekly-planing-notes.png&#34; alt=&#34;Execution and Notes split&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My Weekly Planning subtasks in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;This is my recurring task, scheduled every Sunday. You can see some sub-tasks. I track things I want to do&#xA;during the review and add goals. There are two sections here. One is part of my Overarching Problems: I&#xA;wanted to fix a recurring issue this week, too many things in progress at once. The other is section&#xA;2026-06, my goals for June. I keep them visible every week so I can track where I&amp;rsquo;m heading.&lt;/p&gt;&#xA;&lt;p&gt;Weekly planning focuses mainly on the Execution side. That&amp;rsquo;s where I decide what to deliver and what I don&amp;rsquo;t&#xA;want to miss in the coming week. It&amp;rsquo;s also a reflection on where my time went last week.&lt;/p&gt;&#xA;&lt;p&gt;On top of that I use ad hoc tools for everyday tasks, and for deeper reflection I use paper and physical&#xA;journals.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Tip 3:&lt;/strong&gt;&#xA;Weekly planning must be quick, frictionless, and beneficial. It must also feel good, whatever that means to&#xA;you. You want to enjoy the ritual, otherwise you won&amp;rsquo;t stick to it. Some tricks: go to a café, order your&#xA;favourite coffee, put on music, whatever works. But keep the goal in mind: a prepared set of items with&#xA;priority and status, ready to execute next week.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Tip 4:&lt;/strong&gt;&#xA;The goal of weekly planning is to go from Chaos to Organized Chaos. Organized Chaos is still chaos, but part&#xA;of your system is structured. The rule: work on the organized part as often as possible. It gives you focus.&#xA;Unlike a motivational YouTube video, life keeps throwing surprises. Those go into the Capture part of your&#xA;execution system and are out of scope for weekly planning, unless something has a deadline within a few days,&#xA;in which case it gets included.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;step-1-what-ive-done-last-week&#34;&gt;Step 1: What I&amp;rsquo;ve done last week&lt;/h2&gt;&#xA;&lt;p&gt;First, look at what you completed last week to see where your focus went. Then figure out whether anything&#xA;unfinished is still relevant this week or can be pushed to a later date.&lt;/p&gt;&#xA;&lt;p&gt;In my system I use:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Priorities: P1-P4 and no priority&lt;/li&gt;&#xA;&lt;li&gt;Statuses: To Do, Next, In Progress, Ongoing (longer work or projects), Done, Archived (hidden from view)&lt;/li&gt;&#xA;&lt;li&gt;Dates: Deadline (due date), Start date (when I want to start the task), End date (roughly when I want to&#xA;finish), Updated (when it was last touched, signals it&amp;rsquo;s active), Completed (when it was marked Done)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;For the Last Week view I filter by several date fields:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Deadline, Start date, End date, Updated, Completed (up to today minus 10 days; more than a week, but I&#xA;like a bit more context)&lt;/li&gt;&#xA;&lt;li&gt;For &amp;ldquo;Updated&amp;rdquo; there would be too many items, so I narrow it down by status: In Progress and Ongoing&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/02-filter.png&#34; alt=&#34;Last week filter in 3Monads&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My Last Week filter in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;In 3Monads I can save views with dynamic dates. The &lt;code&gt;today()&lt;/code&gt; value is calculated at open time, so a&#xA;filter like &lt;code&gt;today() - 10 days&lt;/code&gt; always shows the last 10 days without any manual adjustments.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/02-last-week-part2.png&#34; alt=&#34;Last week view in 3Monads, part 2&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My Last Week Done items in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Not everything gets completed. That&amp;rsquo;s normal. This is the moment where I decide what I still want to do&#xA;and what is no longer needed.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/02-last-week-part1.png&#34; alt=&#34;Last week view in 3Monads, part 1&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My Last Week carried over items in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;For anything not yet done that I still want to tackle, I mark it as Next, or In Progress if I&amp;rsquo;ve already&#xA;started. I go through the list to see what I was occupied with and set priorities for things I really want&#xA;to do this week. If priorities are already set, I just highlight them.&lt;/p&gt;&#xA;&lt;p&gt;Some tasks get &amp;ldquo;carried over,&amp;rdquo; not completed again. To avoid the trap of infinite carry-overs, I use a&#xA;few escalation cues:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Counter:&lt;/strong&gt; 3Monads lets me increment or decrement a number on any item (+1 / -1). Each time I&#xA;carry something over, I bump it up. Three or more is a signal: either commit to it this week or drop it.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Highlight:&lt;/strong&gt; I colour-code items to make the most overdue ones impossible to ignore at a glance.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Priority:&lt;/strong&gt; if something keeps slipping, I raise its priority so it competes harder for a slot next week.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Together they make repeat offenders hard to ignore.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;step-2-what-i-want-to-do-this-week&#34;&gt;Step 2: What I want to do this week&lt;/h2&gt;&#xA;&lt;p&gt;I keep two windows open side by side: one with last week, one with this week, so I can control the flow.&#xA;The filter is simple: In Progress, or anything unfinished with a deadline, start date, or end date landing&#xA;in the next 10 days.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/04-this-week-filter.png&#34; alt=&#34;This week filter in 3Monads&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My This Week filter in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Each project and area uses consistently named sections based on the month I plan to do the work. This lets&#xA;me benefit from that convention and get a cross-project view in one place.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/03-choose-status-within-a-project.png&#34; alt=&#34;Choosing status within a project&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My plan for this week in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;I want to finish two books here and have planned two more. I&amp;rsquo;ve already started two things from other&#xA;projects. It&amp;rsquo;s clear what I&amp;rsquo;ve started, what&amp;rsquo;s coming next week, what&amp;rsquo;s high priority and what&amp;rsquo;s not.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;step-3-whats-next-quick-peek&#34;&gt;Step 3: What&amp;rsquo;s next (quick peek)&lt;/h2&gt;&#xA;&lt;p&gt;This peek stops surprises. If something important lands next week, I want to know now, not on Monday&#xA;morning. I filter by Status = Next and P3/P4 with dates between +7 and +17 days. A bit of overlap is&#xA;fine. Everything else gets handled in monthly planning.&lt;/p&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/030/06-next.png&#34; alt=&#34;Next items view&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;My quick peek into the future in &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;utm_medium=blog&amp;utm_campaign=3monads&amp;utm_content=screenshot:030-weekly-planning-in-15-min&#34;&gt;3Monads&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h2 id=&#34;step-4-closing&#34;&gt;Step 4: Closing&lt;/h2&gt;&#xA;&lt;p&gt;At the end I check my Google Calendar for the coming week. Every item with a deadline syncs there too, so&#xA;anything date-driven will show up in the Today view automatically. For everything else I rely on In Progress&#xA;status, then Next with P1 and P2 priorities. It&amp;rsquo;s been my go-to for years and it still works. I especially recommend it for people who have always put off planning because of lack&#xA;of time or because they didn&amp;rsquo;t know where to start and felt overwhelmed.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;summary&#34;&gt;Summary&lt;/h2&gt;&#xA;&lt;p&gt;The most important thing is not the tool. It&amp;rsquo;s the system: the rules, the steps, the habit of doing it.&#xA;Tools matter, but only because they must be frictionless enough to let your system actually run. A tool&#xA;that fights you is a tool you&amp;rsquo;ll stop using.&lt;/p&gt;&#xA;&lt;p&gt;Write your system down. Even a few bullet points. Then follow it. It will change over time, and that&amp;rsquo;s&#xA;fine. A good system changes. That&amp;rsquo;s expected.&lt;/p&gt;&#xA;&lt;p&gt;Pick a day this week. Set a 15-minute timer. Run through the four steps. That&amp;rsquo;s all it takes to start.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Backtested: 16 years, $320k invested. The Magic Formula still has an edge.</title>
      <link>https://lukastymo.com/posts/029-software-engineer-value-investing-magic-formula/</link>
      <pubDate>Mon, 04 May 2026 12:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/029-software-engineer-value-investing-magic-formula/</guid>
      <description>&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-amber-400 bg-amber-50 dark:border-amber-500 dark:bg-amber-950 text-amber-900 dark:text-amber-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ⚠️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Disclaimer&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;I am not a financial advisor. Nothing here is financial advice. All numbers and backtest results are simulated and altered for educational purposes only. Past backtest performance does not guarantee future profits. Do not make investment decisions based on this post.&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;Buffett can&amp;rsquo;t be copied. His edge is intuition built over decades. But what if you could formalize &amp;ldquo;good business, cheap price&amp;rdquo; into an algorithm and let it run? That&amp;rsquo;s what this post is about.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-amber-400 bg-amber-50 dark:border-amber-500 dark:bg-amber-950 text-amber-900 dark:text-amber-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ⚠️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Disclaimer&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;I am not a financial advisor. Nothing here is financial advice. All numbers and backtest results are simulated and altered for educational purposes only. Past backtest performance does not guarantee future profits. Do not make investment decisions based on this post.&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;Buffett can&amp;rsquo;t be copied. His edge is intuition built over decades. But what if you could formalize &amp;ldquo;good business, cheap price&amp;rdquo; into an algorithm and let it run? That&amp;rsquo;s what this post is about.&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;ll walk through how I built a Magic Formula value investing pipeline in Python, what I found after a 16-year backtest, and what I&amp;rsquo;d do differently. Along the way I&amp;rsquo;ll cover the data engineering side: Medallion Architecture, DuckDB audit trails, and Optuna for parameter optimization. If you&amp;rsquo;re not a software person, don&amp;rsquo;t worry. I&amp;rsquo;ll keep the technical parts light.&lt;/p&gt;&#xA;&lt;p&gt;The Magic Formula comes from the book &amp;ldquo;The Little Book That Still Beats the Market.&amp;rdquo; My first issue with it: I&amp;rsquo;d rather work from a scientific paper where tables and charts are reproducible. The book is written for intuition, not the mathematical rigour I needed to build a concrete strategy.&lt;/p&gt;&#xA;&lt;p&gt;LLMs are great for learning, but generating code with them caused a lot of bugs. The model was quietly using proxy values and fallbacks that I only caught after inspecting the full calculation pipeline. Be careful. I recommend splitting the strategy into smaller, self-contained pieces that are easy to test and reason about independently.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;1-value-investing&#34;&gt;1. Value Investing&lt;/h2&gt;&#xA;&lt;p&gt;Some context first. There are different styles of investing. The one used here is value investing. The premise is simple in theory and hard in practice: buy a good business at a cheap price.&lt;/p&gt;&#xA;&lt;p&gt;Buffett, Peter Lynch, David Dodd, and Benjamin Graham spent their lives turning that sentence into usable frameworks. The sad truth: we can&amp;rsquo;t use their frameworks. Any method that reliably generates excess returns gets traded away. That is the core claim of the Efficient Market Hypothesis (EMH).&lt;/p&gt;&#xA;&lt;p&gt;Early value investing focused on book values. It was mostly manual calculation, with the edge coming from doing the work others wouldn&amp;rsquo;t. As EMH predicts, the edge disappears once enough participants adopt the same method, so new techniques had to be invented. The core assumption stayed the same: good business, cheap price. But the definitions evolved.&lt;/p&gt;&#xA;&lt;p&gt;The DCF method appeared. You could discount future cash flows, compare them to the current price, and decide if it was a bargain. Layer in qualitative checks, like whether the business has a moat or good management, and you had a workable value investing approach for the modern era.&lt;/p&gt;&#xA;&lt;p&gt;None of that worked for me though. It all sounds reasonable when you read it, but I couldn&amp;rsquo;t formalize it into an algorithm without years of experience I don&amp;rsquo;t have. Buffett spent decades building that intuition. I needed a different proxy.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;2-greenblatts-magic-formula---what-model-intuition&#34;&gt;2. Greenblatt&amp;rsquo;s Magic Formula - What, Model, Intuition&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/little-book-that-beats-the-market.jpg&#34; alt=&#34;The Little Book That Still Beats the Market by Joel Greenblatt&#34; class=&#34;h-auto&#34; style=&#34;width: 220px;&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;The Little Book That Still Beats the Market by Joel Greenblatt&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h3 id=&#34;the-what&#34;&gt;The What&lt;/h3&gt;&#xA;&lt;p&gt;The method builds a ranking of stocks and rebalances a portfolio of 20-30 positions every year. Each company&amp;rsquo;s rank is based on two factors: cheapness and quality, both defined mathematically by the formula. There are also a few exclusions, because the accounting values the formula relies on are meaningless for certain types of businesses.&lt;/p&gt;&#xA;&lt;p&gt;The method is described in &amp;ldquo;The Little Book That Still Beats the Market.&amp;rdquo; It&amp;rsquo;s short and gives good intuition behind it.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;model&#34;&gt;Model&lt;/h3&gt;&#xA;&#xA;&lt;h4 id=&#34;what-is-cheap-earnings-yield&#34;&gt;What is cheap: Earnings Yield&lt;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Earnings Yield = EBIT / Enterprise Value&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h5 id=&#34;ebit&#34;&gt;EBIT&lt;/h5&gt;&#xA;&lt;p&gt;EBIT is the bottom line just before interest expenses and taxes.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Revenue&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- Operating costs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;= EBIT                ← stops here&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- Interest expense    ← only hits Company B hard&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;= EBT (pre-tax profit)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- Tax&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;= Net income&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Companies have different financial structures. This formula says we don&amp;rsquo;t care whether a company funds itself through equity or debt. Using net income instead of EBIT would penalize debt-funded companies unfairly.&lt;/p&gt;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Company A&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Company B&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;EBIT&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£10M&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£10M&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Interest&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£4M&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Net income&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£10M&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;£6M&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;On net income, B looks 40% worse. On EBIT, they&amp;rsquo;re identical. For the Magic Formula, all other values equal, we treat these two companies as equal.&lt;/p&gt;&#xA;&#xA;&lt;h5 id=&#34;enterprise-value-ev&#34;&gt;Enterprise Value (EV)&lt;/h5&gt;&#xA;&lt;p&gt;Two types of valuation: top-down (what the market thinks the company is worth, i.e., EV) and bottom-up (what it would cost to rebuild the company from scratch).&lt;/p&gt;&#xA;&#xA;&lt;h5 id=&#34;earnings-yield-ey&#34;&gt;Earnings Yield (EY)&lt;/h5&gt;&#xA;&lt;p&gt;Earnings Yield is EBIT divided by Enterprise Value. It answers: for every dollar you pay to own this business, how much profit does it generate per year?&lt;/p&gt;&#xA;&lt;p&gt;EY tells us about cost.&lt;/p&gt;&#xA;&lt;p&gt;Example: if a company&amp;rsquo;s EY is 10, it means that for every \$1 you invest, the business generates \$10 per year.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;what-is-good-return-on-capital&#34;&gt;What is good: Return on Capital&lt;/h4&gt;&#xA;&lt;p&gt;Good means the business uses its capital efficiently:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Return on Capital = EBIT / (Net Fixed Assets + Net Working Capital)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Net Fixed Assets + Net Working Capital is the minimum capital you would need to restart the business from zero and earn the first dollar.&lt;/p&gt;&#xA;&lt;p&gt;Return on Capital tells you how much profit is generated for every dollar permanently tied up in assets. Low ROC: sponge. High ROC: machine. Spending a lot on assets to generate a little profit is much worse than using less capital to generate the same profit.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;tweaks&#34;&gt;Tweaks&lt;/h4&gt;&#xA;&lt;p&gt;The formula is just a model. As the saying goes: all models are wrong, but some are useful. A few more tweaks make the model less wrong.&lt;/p&gt;&#xA;&lt;p&gt;Filter out small caps (below \$50M market cap): they are riskier and less liquid. Some business categories rely heavily on interest income rather than operating earnings. For those, EBIT is a poor measure of value, so we filter them out. Greenblatt recommends filtering out utilities and financial stocks. We also focus on US companies: the market is more mature and has historically performed better. These are reasonable choices for backtesting.&lt;/p&gt;&#xA;&lt;p&gt;Investment horizon: 5-10 years, standard for a value investing strategy.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;intuition&#34;&gt;Intuition&lt;/h3&gt;&#xA;&lt;p&gt;If we buy something good at a cheap price, the odds of profit are higher than with most other approaches. The model defines good and cheap in a simple, algorithmic way, then filters out the obvious cases where the formula breaks down. We want companies with good fundamentals: efficient operations, not heavy spending on assets relative to the profit they generate. By using EBIT, we ignore financing tricks that make a company look better on the bottom line than it actually is.&lt;/p&gt;&#xA;&lt;p&gt;The biggest advantage of this method is taking your own behavior out of the equation. A fixed rebalance date stops you from torpedoing your own portfolio. More importantly, it defines clear buy and sell signals. This protects against gambler&amp;rsquo;s ruin: if you blindly keep buying potential winners, even a winning streak can end with a single bet that wipes everything out. Without a defined exit, you have better odds of ending up at zero.&lt;/p&gt;&#xA;&lt;p&gt;This also gives you systematic exposure to value and quality stocks, which tend to hold up better in volatile conditions. Good companies tend to survive market storms. What makes a company &amp;ldquo;good&amp;rdquo; can mean many things: management quality, competitive moat. The great value investors wrote about all of it, but none of them defined it in a way you can run as an algorithm.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;3-data-architecture-medallion-pipeline-for-financial-data&#34;&gt;3. Data Architecture: Medallion Pipeline for Financial Data&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/server-room-kevinache.jpg&#34; alt=&#34;Data pipeline layers&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/photos/a-rack-of-servers-in-a-server-room-2JJ3wBHu4_0&#34;&gt;Kevin Ache&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h3 id=&#34;medallion-architecture&#34;&gt;Medallion Architecture&lt;/h3&gt;&#xA;&#xA;&lt;h4 id=&#34;bronze&#34;&gt;Bronze&lt;/h4&gt;&#xA;&lt;p&gt;We solve this with a Data Engineering best practice: the Medallion Architecture. It breaks the ranking pipeline into 3 layers:&lt;/p&gt;&#xA;&lt;p&gt;Download raw data and store it in the Bronze layer. We use Sharadar data to eliminate backtesting biases like survivorship bias. Our stock universe is drawn from the Russell 2000 (IWM) holdings.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;silver&#34;&gt;Silver&lt;/h4&gt;&#xA;&lt;p&gt;This layer contains processed data, standardized column names, and intermediate calculations. The pipeline can start from any layer, which speeds up iteration. If you find a mistake in a calculation, fix it and re-run from Silver. No need to re-download the raw data; it&amp;rsquo;s already cached in Bronze.&lt;/p&gt;&#xA;&lt;p&gt;Silver contains all the columns needed to calculate ROC and EY: ebit, market cap, total_debt, cash_and_cash_equivalent, and so on.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;gold&#34;&gt;Gold&lt;/h4&gt;&#xA;&lt;p&gt;With all components in place, we calculate ROC and EY and produce the ranking. The result goes into the Gold layer: the ordered list the portfolio acts on in live trading.&lt;/p&gt;&#xA;&lt;p&gt;It contains ey_rank, roc_rank, and combined_rank (their sum). Tickers are sorted by combined_rank. We buy the top 20.&lt;/p&gt;&#xA;&lt;p&gt;Splitting into 3 layers makes debugging fast. If a value looks wrong, you know which layer produced it and which code to check.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;coding-and-data-principles&#34;&gt;Coding and Data Principles&lt;/h3&gt;&#xA;&lt;p&gt;Do not default to null or 0. If something unexpected happens, fail fast. That forces a conscious choice about what the fallback should be.&lt;/p&gt;&#xA;&lt;p&gt;On top of fail-fast, I added automatic data quality checks using Pydantic. You define a schema for your values and catch mistakes in the algorithm early.&lt;/p&gt;&#xA;&lt;p&gt;Single Responsibility and Separation of Concerns are non-negotiable here. Small, focused modules are easy to test and easy to reason about.&lt;/p&gt;&#xA;&lt;p&gt;Keep the code simple. Simpler code has fewer bugs, by definition. Initially I planned to use Sharadar for backtesting and yfinance for live runs. That turned out to be a mistake. Two code branches meant two sets of assumptions, and Yahoo Finance makes different adjustments than Sharadar. The backtest was testing a different method than what I was using to invest. The fix was obvious: use the same data source for both. Fewer lines of code, more reliable results.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;risk-tracker&#34;&gt;Risk tracker&lt;/h3&gt;&#xA;&lt;p&gt;Any improvements and code changes will require assumptions that might be wrong. I track those in README.md for future review.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;risk-1-and-2-data-quality-and-bugs-in-code&#34;&gt;Risk 1 and 2: Data quality and bugs in code&lt;/h4&gt;&#xA;&lt;p&gt;Risk 1: the data source has bugs. Risk 2: my code has bugs.&lt;/p&gt;&#xA;&lt;p&gt;For Risk 1, research showed retail investors are generally satisfied with Sharadar&amp;rsquo;s quality. Nasdaq acquiring Sharadar is also a reasonable signal.&lt;/p&gt;&#xA;&lt;p&gt;For Risk 2, the mitigation is the engineering practices described above, plus the DuckDB audit database: every ticker, date, and value is queryable, with a JSON log showing exactly how each number was calculated.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;risk-3-overfitting&#34;&gt;Risk 3: Overfitting&lt;/h4&gt;&#xA;&lt;p&gt;My configuration file for backtesting looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-gdscript3&#34; data-lang=&#34;gdscript3&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;backtest&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Year range (inclusive) for annual rebalancing.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;start_year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2010&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;end_year&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2025&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Rebalance date in each year.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;rebalance_month&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;7&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;rebalance_day&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Hold top N names by combined rank.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;top_n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Amount invested at the start of each year (same currency as your prices).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;annual_contribution&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;_000&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# One-way transaction fee applied at each rebalance leg (sell + buy = 2x).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0.001 = 0.1% per leg, typical for a discount broker.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Set to 0 to disable.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;transaction_fee_pct&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.001&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Annual risk-free rate used for Sharpe ratio calculation.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Use the average short-term T-bill rate for your backtest period.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0.04 = 4% (reasonable for 2000-2024 average), set to 0 to get raw return/vol.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;risk_free_rate&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.04&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Size of annual universe before Magic Formula ranking (approx Russell 1000).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;universe_n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2000&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Skip the top-N largest companies before sampling universe_n.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# e.g. universe_offset = 1000 → exclude the 1 000 biggest (mega caps),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# then take the next 3 000 (ranks 1 001–4 000 by market cap).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Set to 0 to include all sizes from the top.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#universe_offset = 200&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;universe_offset&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Benchmark ticker used for yearly comparison.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#benchmark_ticker = &amp;#34;IWB&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;benchmark_ticker&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;IWM&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Backtest bronze controls (same meaning as pipeline).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;skip_bronze&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;false&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;force&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;false&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Write signal audit rows to audit.duckdb after each backtest year.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Disable for faster iteration when you don&amp;#39;t need to query the audit DB.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Old audit rows are always cleared at the start of a run regardless of this setting.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;write_audit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;bp&#34;&gt;false&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;backtest&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;screens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Sortino filter — require trailing-12-month Sortino ratio &amp;gt;= threshold&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0.0 means disabled. Typical enabled value: 0.4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sortino_min&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sortino_window_days&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;252&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Momentum filter — require price above SMA and/or positive 12-1 momentum&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0 means disabled for each leg independently&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;momentum_sma_days&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;momentum_lookback_months&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Piotroski-style quality filter — require quality score &amp;gt;= threshold (0-5 scale).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Criteria use only the SF1 columns available in the Sharadar extract:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#   Q1 EBIT &amp;gt; 0  Q2 EBIT improved YoY  Q3 debt decreased  Q4 current ratio improved  Q5 no dilution&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0 means disabled. Typical enabled value: 3 (require 3 out of 5).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;piotroski_min&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Composite value filter — keep only tickers in the cheapest top_pct% by a multi-ratio value score.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Three signals are percentile-ranked and averaged (Gray / Alpha Architect approach):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#   V1 EBIT/EV   (earnings yield — Magic Formula&amp;#39;s own metric)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#   V2 EBIT/P    (P/E proxy using EBIT)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;#   V3 BV/P      (book-to-price proxy: (current_assets - current_liabilities + net_PP&amp;amp;E) / mktcap)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# 0 means disabled. Typical enabled value: 50 (keep the cheaper half of the ranked universe).&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;composite_value_top_pct&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Tuning those parameters until the backtest looks good is parameter hacking. To catch overfitting, I ran the full backtest on different rebalance dates. If a parameter set is truly overfit, good results on one date will collapse on another.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;composite_value_top_pct&lt;/code&gt; and &lt;code&gt;momentum_lookback_months&lt;/code&gt; are the two I learned to disable. They improved results on one specific rebalance date but fell apart when the date changed. The momentum filter was effectively turning the strategy into a momentum strategy, not a Magic Formula strategy. That&amp;rsquo;s scope creep, not an improvement.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;4-performance-engineering-vectorisation-and-parallelism&#34;&gt;4. Performance Engineering: Vectorisation and Parallelism&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/fiber-optics-kashishlamba.jpg&#34; alt=&#34;Parallel computing and processing speed&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/photos/abstract-blue-glowing-fiber-optics-with-bokeh-effect-DGwunSOMMbk&#34;&gt;Kashish Lamba&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Why this matters: naively screening 2000 tickers with a row-by-row Python loop takes minutes; the vectorised + parallel version takes seconds.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;medallion-architecture-separates-network-heavy-from-compute-heavy-operations&#34;&gt;Medallion Architecture separates network-heavy from compute-heavy operations&lt;/h3&gt;&#xA;&lt;p&gt;It separates slow network operations (downloading stock data) from offline computation. The goal is fast iteration on the backtest, since you tweak it constantly.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;vectorisation-beats-for-loop&#34;&gt;Vectorisation beats for-loop&lt;/h3&gt;&#xA;&lt;p&gt;Matrix multiplication is much faster than row-by-row loops because it can be parallelized, unlike for-loop operations on dataframes.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;parallel-everything-you-can&#34;&gt;Parallel everything you can&lt;/h3&gt;&#xA;&lt;p&gt;Some computations can run in parallel: matrix operations, and preparing the Bronze layer (with rate-limit protection and exponential backoff).&lt;/p&gt;&#xA;&lt;p&gt;Parallelism also helped with Optuna, which searches for optimal weights for the Sortino and Piotroski filters.&lt;/p&gt;&#xA;&lt;p&gt;One caveat: parallel threads share the same Bronze/Silver/Gold folders. Make sure threads do not overwrite each other&amp;rsquo;s output.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;5-define-experiment&#34;&gt;5. Define experiment&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/trader-screens-jakubzerdzicki.jpg&#34; alt=&#34;Backtesting with trading screens&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/photos/trader-analyzing-stock-market-charts-on-computer-screens-with-calculator--DWqOL_d91I&#34;&gt;Jakub Żerdzicki&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&#xA;&lt;h3 id=&#34;setup&#34;&gt;Setup&lt;/h3&gt;&#xA;&lt;p&gt;Before running an experiment, define it.&lt;/p&gt;&#xA;&lt;p&gt;We add \$20,000 per year on the rebalance date, sell all positions, and buy new ones based on the updated ranking (top 20 stocks).&lt;/p&gt;&#xA;&lt;p&gt;Transaction fee: 0.1% per leg. Risk-free rate: 4%. Backtest period: 2010-2025. The period covers COVID, is recent enough to be relevant, and includes about 5 years of data after the method became widely known.&lt;/p&gt;&#xA;&lt;p&gt;The benchmark is the whole universe we are investing in: Russell 2000 (IWM). We also compare against IWB (Russell 1000, large caps) as a broader market reference, a harder bar since large caps are more efficiently priced.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;metrics&#34;&gt;Metrics&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;CAGR&lt;/strong&gt; (Compound Annual Growth Rate): the constant annual rate that would produce the same end result. It normalizes growth over time.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;MWR&lt;/strong&gt; (Money-Weighted Return): weights returns by how much capital was deployed at each point in time. Large deposits before good periods amplify returns; large deposits before bad periods drag them down.&lt;/li&gt;&#xA;&lt;li&gt;Example for CAGR and MWR:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Start: £100, drops 50% → £50. You add £100 → £150. Then rises 100% → £300.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;CAGR&lt;/strong&gt;: measures strategy performance. What was the annual growth rate, independent of your deposits?&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;MWR&lt;/strong&gt;: in practice, it matters whether the strategy performs better when your capital is small versus when it&amp;rsquo;s large. MWR captures this. It&amp;rsquo;s higher when the strategy performs well while more capital is deployed.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Sharpe&lt;/strong&gt;: profit per unit of risk. Higher is better. We want at least as much return per unit of risk as the benchmark.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Min Survivors&lt;/strong&gt;: some filter configurations remove too many tickers. This shows the lowest count that remained in any single year.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Max Drawdown&lt;/strong&gt;: the largest loss from peak to trough.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Win Rate&lt;/strong&gt;: the percentage of years the portfolio beat the benchmark.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Final Profit&lt;/strong&gt;: what we actually earned after transaction fees, minus total capital invested.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3 id=&#34;variants&#34;&gt;Variants&lt;/h3&gt;&#xA;&lt;p&gt;The vanilla Magic Formula is getting old. A few improvements have been published over the years that I wanted to optionally add, at least in a limited form. I turned them on lightly, just enough to filter out the most obvious value traps.&lt;/p&gt;&#xA;&lt;p&gt;Improvements tested:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Sortino: return per unit of downside volatility. Better than Sharpe because it only penalizes losses, not gains.&lt;/li&gt;&#xA;&lt;li&gt;Piotroski F-score: scores companies on financial health. I use a small subset of it to filter out the clearly bad ones.&lt;/li&gt;&#xA;&lt;li&gt;Momentum: did not help, disabled.&lt;/li&gt;&#xA;&lt;li&gt;Composite Value Filter: same result, disabled.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2 id=&#34;6-audit-trail-verifying-every-single-calculation&#34;&gt;6. Audit Trail: Verifying Every Single Calculation&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/financial-data-danielbrzdek.jpg&#34; alt=&#34;Financial data on screen&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/photos/financial-stock-market-data-displayed-on-a-screen-EuIqk6LpUU0&#34;&gt;Daniel Brzdęk&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;DuckDB is a Python library that gives you an analytical database. Think SQLite, but built for analytical queries: aggregations, window functions, large scans. No server needed; it runs in-process.&lt;/p&gt;&#xA;&lt;p&gt;Adding DuckDB changed everything. Auditing every calculation helped me understand the model and cross-check results against alternative data sources. Every pipeline run writes to &lt;code&gt;audit.duckdb&lt;/code&gt;, a full ledger with an explanation for every number.&lt;/p&gt;&#xA;&lt;p&gt;When I see a suspicious value in the report, I can trace its full lineage: what formula produced it, what inputs went in. I can also feed the audit output to an LLM and ask if anything looks off. This caught dozens of bugs, particularly differences between yfinance and Sharadar data.&lt;/p&gt;&#xA;&lt;p&gt;Example: FLR audit trail:&#xA;&lt;a href=&#34;https://lukastymo.com/images/posts/029-flr-audit-trail.png&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/029-flr-audit-trail.png&#34; alt=&#34;FLR audit trail&#34;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Every value is traceable. For example: earnings_yield for FLR on 2012-07-01, built from ebit / ev, where silver.ebit=916321000.0 and gold.ev=5878382636.0.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;7-automatic-parameter-optimisation-optuna&#34;&gt;7. Automatic Parameter Optimisation: Optuna&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/029/data-viz-loganvoss.jpg&#34; alt=&#34;Optimization and hyperparameter search&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/photos/abstract-glowing-lines-forming-a-complex-data-visualization-20BjhzK9Nxs&#34;&gt;Logan Voss&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;Optuna is an open-source Python hyperparameter optimization framework. I used it to find the best values for the Sortino threshold and Piotroski minimum score. It&amp;rsquo;s much faster than brute force because it uses Bayesian search (TPE sampler) rather than testing every combination.&lt;/p&gt;&#xA;&lt;p&gt;To guard against overfitting, I ran the strategy with the tuned parameters on different rebalance dates. First manually, checking each result. Then automatically across all 12 months (1st day of each month), generating a probability distribution.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;_adv&lt;/code&gt; = advantage. Positive means the Magic Formula portfolio beat the IWB benchmark.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 1/12]  Jan-01 ...  cagr_adv=-2.1%  mwr_adv=-4.3%  win_rate=38%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 2/12]  Feb-01 ...  cagr_adv=-0.8%  mwr_adv=-1.6%  win_rate=25%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 3/12]  Mar-01 ...  cagr_adv=-2.5%  mwr_adv=-3.6%  win_rate=38%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 4/12]  Apr-01 ...  cagr_adv=+1.2%  mwr_adv=+0.8%  win_rate=50%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 5/12]  May-01 ...  cagr_adv=-1.3%  mwr_adv=-1.7%  win_rate=44%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 6/12]  Jun-01 ...  cagr_adv=+1.0%  mwr_adv=+1.2%  win_rate=50%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 7/12]  Jul-01 ...  cagr_adv=+1.5%  mwr_adv=+1.9%  win_rate=50%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 8/12]  Aug-01 ...  cagr_adv=+0.7%  mwr_adv=+0.6%  win_rate=44%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [ 9/12]  Sep-01 ...  cagr_adv=-1.4%  mwr_adv=-2.6%  win_rate=56%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [10/12]  Oct-01 ...  cagr_adv=-4.7%  mwr_adv=-5.1%  win_rate=38%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [11/12]  Nov-01 ...  cagr_adv=-4.9%  mwr_adv=-5.8%  win_rate=31%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  [12/12]  Dec-01 ...  cagr_adv=-2.3%  mwr_adv=-4.0%  win_rate=44%&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This particular run still had momentum enabled. The sweep revealed it was the culprit: momentum parameters that looked great on July rebalance collapsed on most other dates. That sensitivity to entry timing is the classic overfitting signal.&lt;/p&gt;&#xA;&lt;p&gt;Once momentum was disabled and only Sortino and Piotroski were kept, the results stabilised. April, June, July, and August show the strongest months — consistent with known seasonal effects around earnings season. The final configuration used in Appendix 2 and 3 is July rebalance, which sits in that better-performing window.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;8-summary&#34;&gt;8. Summary&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Beating the benchmark is hard.&lt;/li&gt;&#xA;&lt;li&gt;Beating it on historical data says nothing about the future. But it does show whether the method ever had an edge.&lt;/li&gt;&#xA;&lt;li&gt;Backtesting is hard. It involves a lot of assumptions and a lot of data. But once built properly, the framework can be reused for other strategies.&lt;/li&gt;&#xA;&lt;li&gt;Know what kind of investor you are. If my method slightly underperforms the benchmark but is more volatile, I might still prefer it. Consistently betting on value stocks in a volatile market is the kind of bet I want for my riskier portfolio.&lt;/li&gt;&#xA;&lt;li&gt;Benchmarks are powerful. Given that, it makes sense to hold multiple portfolios: one that simply tracks the benchmark, avoids all the risks mentioned here, and bets on a long horizon with no behavioral interference. And a separate portfolio for systematic stock picking, which works for me. It satisfies my need to do the math. It also solves the behavioral problem by delegating decisions to an algorithm, which means I&amp;rsquo;m less likely to sabotage my other portfolios where I use different strategies.&lt;/li&gt;&#xA;&lt;li&gt;Auditability is non-negotiable. A final ranking means nothing if you can&amp;rsquo;t trace how each number was calculated and spot-check a sample.&lt;/li&gt;&#xA;&lt;li&gt;Vanilla Magic Formula did not outperform Russell 1000 over the 16-year backtest. The method has been widely published; the edge is gone. With Sortino and Piotroski filters, the edge comes back: +4.8% CAGR over IWM (same universe) and +1.5% over IWB (large caps).&lt;/li&gt;&#xA;&lt;li&gt;The clearest lesson: regular investing works. Whether you use Magic Formula or just buy the benchmark, contributing \$320,000 over 16 years turned into over \$1M — vs \$794k for IWM and \$1.17M for IWB.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;appendix-1-magic-formula-backtesting-config&#34;&gt;Appendix 1. Magic Formula Backtesting config&lt;/h2&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;start_year&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2010&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;end_year&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2025&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;rebalance_month&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;rebalance_day&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;top_n&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;benchmark_ticker&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;IWM&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&amp;mdash; Universe &amp;mdash;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;universe_n&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;universe_offset&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&amp;mdash; Filters &amp;mdash;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;min_market_cap&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;50000000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;max_market_cap&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;excluded_sectors&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Financials, Utilities, Real Estate, Financial Services&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;excluded_industries&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Insurance, Managed Care, Healthcare Plans, Insurance—Life, Insurance—Property &amp;amp; Casualty, Insurance—Specialty, Insurance—Diversified, Insurance Brokers&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&amp;mdash; Contributions &amp;amp; Fees &amp;mdash;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;annual_contribution&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;transaction_fee_pct&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.001&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;risk_free_rate&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.04&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&amp;mdash; Overlays &amp;mdash;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.sortino_min&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.2&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.sortino_window_days&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;252&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.momentum_sma_days&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.momentum_lookback_months&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.piotroski_min&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;screens.composite_value_top_pct&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&#xA;&lt;h2 id=&#34;appendix-2--magic-formula-backtesting-2010---2025&#34;&gt;Appendix 2.  Magic Formula backtesting 2010 - 2025&lt;/h2&gt;&#xA;&lt;p&gt;IWB = Russell 1000 (large caps). IWM = Russell 2000 (small caps, same universe as portfolio).&lt;/p&gt;&#xA;&#xA;&lt;div class=&#34;full-bleed not-prose my-6 font-sans&#34;&gt;&#xA;  &lt;div class=&#34;full-bleed-inner&#34;&gt;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;year&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;as_of_date&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;n_holdings&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;n_survivors&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;portfolio_return&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWB return&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWM return&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;annual_contribution&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;total_contributed&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;portfolio_value&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWB value&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWM value&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;portfolio_profit&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWB profit&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;IWM profit&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2010&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2010-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;804&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;44.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;34.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;40.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;28,933&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;26,800&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;28,064&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8,933&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6,800&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8,064&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2011&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2011-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;925&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-6.7%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-2.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;40,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;45,551&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;48,202&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;46,911&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;5,551&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8,202&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6,911&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2012&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2012-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;472&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;26.5%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;21.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;24.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;60,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;82,780&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;82,943&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;83,224&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;22,780&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;22,943&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;23,224&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2013&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2013-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;776&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;23.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;24.7%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;22.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;80,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;127,029&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;128,340&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;126,882&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;47,029&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;48,340&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;46,882&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2014&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2014-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;790&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;12.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7.7%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6.2%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;100,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;165,666&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;159,825&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;155,923&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;65,666&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;59,825&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;55,923&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2015&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2015-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;536&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-1.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-6.5%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;120,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;182,380&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;183,937&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;164,474&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;62,380&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;63,937&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;44,474&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2016&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2016-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;449&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;19.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;18.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;25.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;140,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;241,050&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;240,546&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;230,665&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;101,050&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;100,546&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;90,665&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2017&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2017-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;681&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8.5%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;14.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;17.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;160,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;282,556&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;298,073&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;294,664&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;122,556&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;138,073&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;134,664&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2018&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2018-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;629&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;10.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-3.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;180,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;321,818&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;351,227&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;302,637&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;141,818&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;171,227&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;122,637&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2019&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2019-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;465&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-7.5%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7.1%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-7.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;200,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;315,461&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;397,688&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;297,347&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;115,461&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;197,688&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;97,347&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2020&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2020-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;360&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;55.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;42.7%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;64.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;220,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;521,027&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;596,022&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;523,182&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;301,027&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;376,022&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;303,182&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;700&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-13.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-12.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-25.1%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;240,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;465,234&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;538,518&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;406,727&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;225,234&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;298,518&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;166,727&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2022&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2022-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;286&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;37.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;18.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;260,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;663,441&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;658,876&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;474,789&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;403,441&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;398,876&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;214,789&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2023&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2023-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;713&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;23.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;23.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8.7%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;280,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;841,503&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;841,016&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;537,852&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;561,503&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;561,016&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;257,852&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2024&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2024-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;518&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;21.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;15.2%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;9.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;300,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,048,224&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;991,602&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;611,433&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;748,224&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;691,602&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;311,433&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2025&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2025-07-01&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;524&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;31.4%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;15.2%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;25.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;320,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,401,079&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,165,683&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;794,343&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,081,079&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;845,683&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;474,343&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Average&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;601.75&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;17.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;15.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;13.2%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&lt;h2 id=&#34;appendix-3-magic-formula-backtesting-metrics&#34;&gt;Appendix 3. Magic Formula backtesting metrics&lt;/h2&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Portfolio&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;vs IWB (Russell 1000)&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;vs IWM (Russell 2000)&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Annual Contribution&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;20,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Transaction Fee (per leg)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.1%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Risk-Free Rate (annual)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;4.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Total Years&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;16&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Total Contributed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;320,000&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;CAGR (time-weighted)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;16.1%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;14.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11.3%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;CAGR Advantage&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;+1.5%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;+4.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;MWR / IRR (money-weighted)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;15.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;14.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;10.0%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;MWR Advantage&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;+1.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;+5.9%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Sharpe (annual)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.697&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.868&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;0.429&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Sharpe Advantage&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-0.171&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;+0.268&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Max Drawdown&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-13.8%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-12.6%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;-25.1%&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Win Rate&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;—&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;50% (8/16)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;75% (12/16)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Final Value&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,401,079&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,165,683&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;794,343&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Profit&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1,081,079&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;845,683&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;474,343&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Avg Survivors / Year&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;601.75&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Min Survivors / Year&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;286&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Positive CAGR and MWR advantage against both benchmarks. Against IWM (same universe): +4.8% CAGR, 75% win rate. Against IWB (large caps): +1.5% CAGR, 50% win rate.&lt;/li&gt;&#xA;&lt;li&gt;Sharpe is better than IWM (+0.268) but worse than IWB (-0.171). The portfolio takes on more volatility than large caps but less than small caps.&lt;/li&gt;&#xA;&lt;li&gt;Max Drawdown: much better than IWM (-13.8% vs -25.1%). The filters removed most of the worst small-cap crashes.&lt;/li&gt;&#xA;&lt;li&gt;Win rate 75% vs IWM. The strategy consistently picks better small caps than the index.&lt;/li&gt;&#xA;&lt;li&gt;Portfolio profit: \$1,081,079 vs \$845,683 (IWB) and \$474,343 (IWM). That&amp;rsquo;s \$235,396 more than large caps and \$606,736 more than the small-cap index over 16 years.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-blue-300 bg-blue-50 dark:border-blue-600 dark:bg-blue-950 text-blue-900 dark:text-blue-100 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      💬&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Need help building your strategy?&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;Scala, Python, Haskell, Spark. I build quant pipelines and deploy them to production. You focus on the alpha, I&amp;rsquo;ll handle the engineering. &lt;a href=&#34;mailto:lukas@codeily.com&#34;&gt;lukas@codeily.com&lt;/a&gt;&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&#xA;&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;&#xA;&lt;p&gt;Sources:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Magic_formula_investing&#34;&gt;Magic formula investing - Wikipedia&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;The Little Book That Still Beats the Market by Joel Greenblatt&lt;/li&gt;&#xA;&lt;li&gt;My personal backtesting and ETL pipeline framework (contact me at &lt;a href=&#34;mailto:lukas@codeily.com&#34;&gt;lukas@codeily.com&lt;/a&gt; if you&amp;rsquo;re interested in working together)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Stateful Kafka Streams Processors: Reducing Rebalancing - Lessons Learned</title>
      <link>https://lukastymo.com/posts/028-stateful-kafka-stream-processors/</link>
      <pubDate>Thu, 16 Apr 2026 12:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/028-stateful-kafka-stream-processors/</guid>
      <description>&lt;p&gt;Stateful Kafka Streams on Kubernetes need configuration to stay stable during rolling updates without causing lag. If your processor must be fast, runs on few partitions, and short lag matters, the defaults are not enough. Enable static membership with a timeout based on the worst-case duration of your rolling updates.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;Stateful Kafka Streams on Kubernetes need configuration to stay stable during rolling updates without causing lag. If your processor must be fast, runs on few partitions, and short lag matters, the defaults are not enough. Enable static membership with a timeout based on the worst-case duration of your rolling updates.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;fundamentals&#34;&gt;Fundamentals&lt;/h2&gt;&#xA;&lt;p&gt;Kafka Streams was designed for building mission-critical real-time applications and microservices (&lt;a href=&#34;https://kafka.apache.org/42/streams/introduction/&#34;&gt;kafka.apache.org&lt;/a&gt;). It is used when both input and output data live in Kafka clusters.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;kafka-cluster&#34;&gt;Kafka Cluster&lt;/h3&gt;&#xA;&lt;p&gt;In a distributed system, multiple computers communicate over the network but appear as one system. In Kafka, a cluster is a group of servers working together. A Kafka cluster needs a few components to work: brokers, partitions, and replication (&lt;a href=&#34;https://www.confluent.io/blog/what-is-an-apache-kafka-cluster/&#34;&gt;confluent.io&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;terminology&#34;&gt;Terminology&lt;/h4&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Distributed Concept&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Kafka Streams&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Kafka Core&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Worker&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Stream Application instance&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Consumer Instance&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Unit of work&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Task&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;You define it (poll loop)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;State&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;State Store (managed)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;You manage it (DB, memory)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Threading&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;StreamThread&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;You manage it&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Partition assignment&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Automatic per task&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Partition assignment (same mechanism)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;div class=&#34;not-prose mt-3 mb-3 text-sm text-gray-500 dark:text-gray-400 font-sans leading-snug&#34;&gt;&#xA;    &lt;span class=&#34;uppercase tracking-wider&#34;&gt;Source&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;Claude, Sonnet 4.6&lt;/span&gt;&lt;/div&gt;&#xA;&#xA;&lt;h4 id=&#34;replication-and-brokers&#34;&gt;Replication and Brokers&lt;/h4&gt;&#xA;&lt;p&gt;In distributed systems, we design for the loss of any computer at any time. That event must not cause data loss. Replication solves this problem. The pattern uses a leader and followers. Followers stay in sync with the leader and keep a copy of the data. In distributed systems, a computer that is part of the cluster is called a node.&lt;/p&gt;&#xA;&lt;p&gt;A broker does compute. It handles replication, reads and writes, leader election, and offset management. When you write a consumer or producer app and deploy it to a pod, that pod contains business logic and internally calls &lt;code&gt;consumer.poll()&lt;/code&gt; or &lt;code&gt;producer.send()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;If you have multiple Kafka producers, consumers, and stream processors, they each run in their own pods. But all of them talk to a common set of brokers, which are shared infrastructure. When you produce a message, you logically send it to a topic. But the partition for that topic lives in a broker.&lt;/p&gt;&#xA;&lt;p&gt;With 3 brokers, partition distribution looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Broker-0: Partition-0 (leader), Partition-1 (follower), Partition-2 (follower)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Broker-1: Partition-1 (leader), Partition-0 (follower), Partition-2 (follower)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Broker-2: Partition-2 (leader), Partition-0 (follower), Partition-1 (follower)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Multiple leader partitions per broker are common when the number of partitions exceeds the number of brokers.&lt;/p&gt;&#xA;&lt;p&gt;Each partition is copied for durability. The number of copies is controlled by &lt;code&gt;replicationFactor&lt;/code&gt;. The Apache Kafka default is 1, but production clusters almost always use 3. With &lt;code&gt;replicationFactor = 2&lt;/code&gt;, partition 0 of Topic A lives on two brokers: one leader, one follower.&lt;/p&gt;&#xA;&lt;p&gt;What happens if a broker fails? The Kafka controller elects a new leader from the remaining in-sync replicas. KRaft (KIP-500) is the system that keeps the controller itself highly available, replacing ZooKeeper in Kafka 3.3+. If all replicas for a partition are lost, that data is gone.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s pause and sum up. In a Kafka cluster, the shared infrastructure is the brokers. Producers, consumers, and processors all communicate through topics and partitions on that shared infrastructure. To keep data durable, we use replication: copies are stored across brokers. The controller promotes a follower to leader if a broker fails.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;topics-partitions-consumer-groups-offsets-and-lag&#34;&gt;Topics, Partitions, Consumer Groups, Offsets, and Lag&lt;/h4&gt;&#xA;&lt;p&gt;A topic is like a table in a database: it stores data under a name. That data is split into physical buckets called partitions. Multiple partitions can live in a single broker.&lt;/p&gt;&#xA;&lt;p&gt;Producers write data to topics. Each topic is consumed by consumers within consumer groups. A consumer group tracks where each consumer finished consuming via an offset. The distance to the latest message is called lag.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;kafka-streams-vs-kafka-core&#34;&gt;Kafka Streams vs Kafka Core&lt;/h3&gt;&#xA;&lt;p&gt;In Kafka Core, you write low-level code to manage everything yourself. You call &lt;code&gt;consumer.poll()&lt;/code&gt; to get messages and store them in Redis or Postgres. Kafka Core is just a client library.&lt;/p&gt;&#xA;&lt;p&gt;As computation grows more complex, you start building wrappers on top of the low-level Kafka client. Imagine you want to count words in a stream. With Kafka Core, you need:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;consumer.poll()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── groupBy key + count&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── upsert to database&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── race conditions        (2 instances update same key)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── duplicate processing   (what if app crashes mid-upsert?)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── rebalance problem      (partition moves to another instance, state stays in DB but local cache is lost)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └── consistency            (local count vs global count out of sync)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;These are distributed problems that would be tedious and risky to solve in every computation unit. That is where Kafka Streams comes in.&lt;/p&gt;&#xA;&lt;p&gt;Kafka Streams provides a high-level wrapper around the low-level Kafka client that solves those distributed problems for you. The same problem in Kafka Streams is a one-liner:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;stream&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  .groupByKey()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  .count()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h3 id=&#34;kafka-core&#34;&gt;Kafka Core&lt;/h3&gt;&#xA;&#xA;&lt;h4 id=&#34;consumer-group&#34;&gt;Consumer Group&lt;/h4&gt;&#xA;&lt;p&gt;Each consumer works within a consumer group: a set of consumers that consume from the same topic. This enables parallelism. With 4 partitions and 4 consumers, each consumer handles exactly one partition, giving a parallelism factor of 4. Different consumer groups can consume from the same partitions independently, because each group maintains its own offset.&lt;/p&gt;&#xA;&lt;p&gt;The consumer group is a fundamental Kafka concept. It lets you guarantee ordering, which is both important and tricky in distributed systems. Order is guaranteed only within a single partition.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;rebalance&#34;&gt;Rebalance&lt;/h3&gt;&#xA;&lt;p&gt;Rebalance is the process that assigns partitions to consumers. The Group Coordinator, which is part of the broker, handles this.&lt;/p&gt;&#xA;&lt;p&gt;Example with 4 partitions and 3 consumers in the consumer group:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Consumer 0 -&amp;gt; Partition-0, Partition-1&lt;/li&gt;&#xA;&lt;li&gt;Consumer 1 -&amp;gt; Partition-2&lt;/li&gt;&#xA;&lt;li&gt;Consumer 2 -&amp;gt; Partition-3&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;When does it happen? When a new consumer joins or leaves the group.&lt;/p&gt;&#xA;&lt;p&gt;To reassign partitions, the Group Coordinator first stops all consumers from polling. They resume only after reassignment is complete. This is the stop-the-world rebalance. Kafka 2.4 introduced cooperative rebalancing (KIP-429), enabled by default from Kafka 3.1. It stops only the partitions that need to move, not all of them.&lt;/p&gt;&#xA;&lt;div class=&#34;not-prose mt-3 mb-3 text-sm text-gray-500 dark:text-gray-400 font-sans leading-snug&#34;&gt;&#xA;    &lt;span class=&#34;uppercase tracking-wider&#34;&gt;Source&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;Claude, Sonnet 4.6&lt;/span&gt;&lt;/div&gt;&#xA;&#xA;&lt;h3 id=&#34;kafka-streams&#34;&gt;Kafka Streams&lt;/h3&gt;&#xA;&#xA;&lt;h4 id=&#34;topology&#34;&gt;Topology&lt;/h4&gt;&#xA;&lt;p&gt;Your application code defines a Topology, which is a DAG (Directed Acyclic Graph). It contains your entire processing pipeline:&lt;/p&gt;&#xA;&lt;p&gt;Source (topic) -&amp;gt; Processor1 -&amp;gt; Processor2 -&amp;gt; &amp;hellip; -&amp;gt; ProcessorN -&amp;gt; Sink (topic)&lt;/p&gt;&#xA;&lt;p&gt;We consume from a topic, process the data through multiple processors, and produce to a different output topic. The topology describes what happens to the data at each step.&lt;/p&gt;&#xA;&lt;p&gt;Word Count example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Source(&amp;#34;input-topic&amp;#34;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── FlatMapValues (split sentence into words)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── GroupByKey&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── Count  (stateful processor, uses state store)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── Sink(&amp;#34;output-topic&amp;#34;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h4 id=&#34;processor&#34;&gt;Processor&lt;/h4&gt;&#xA;&lt;p&gt;A single component in the topology is called a processor. A processor does one thing. There are two types:&lt;/p&gt;&#xA;&lt;p&gt;Stateless processors:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;filter&lt;/li&gt;&#xA;&lt;li&gt;map&lt;/li&gt;&#xA;&lt;li&gt;flatMap&lt;/li&gt;&#xA;&lt;li&gt;branch&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Stateful processors:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;count&lt;/li&gt;&#xA;&lt;li&gt;aggregate&lt;/li&gt;&#xA;&lt;li&gt;join&lt;/li&gt;&#xA;&lt;li&gt;reduce&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The word count example needs stateful processors for aggregation.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;task&#34;&gt;Task&lt;/h4&gt;&#xA;&lt;p&gt;A task is one instance of the topology running against a single partition. It is the unit of parallelism.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;state-and-durability-in-kafka-streams&#34;&gt;State and Durability in Kafka Streams&lt;/h4&gt;&#xA;&lt;p&gt;Kafka Core requires low-level coding. To store state, you would need an external store like Postgres or Redis. Kafka Streams includes all of this, with the hard distributed problems solved for you.&lt;/p&gt;&#xA;&lt;p&gt;Where is the magic? There is none. Kafka Streams uses RocksDB, a disk-based embedded database. The Kafka cluster ensures data durability through replication across brokers. With disk-based storage, durability is already guaranteed by the cluster.&lt;/p&gt;&#xA;&lt;p&gt;Kafka Streams adds one more layer: an internal topic called the changelog. It applies the Event Sourcing pattern: an ordered log of modifications that can be replayed to rebuild state.&lt;/p&gt;&#xA;&lt;p&gt;Pure event sourcing is just a list of changes. Over time, this list grows and becomes slow to replay. Event sourcing solves this with snapshotting: periodically converting the event list into a snapshot, from which further events are replayed. In Kafka, this is handled by log compaction: it keeps only the latest value for each key, which is exactly what the internal state store needs.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;rebalance-in-kafka-streams&#34;&gt;Rebalance in Kafka Streams&lt;/h4&gt;&#xA;&lt;p&gt;Rebalancing in Kafka Streams works the same way as in Kafka Core, but stateful applications have state attached to each partition.&lt;/p&gt;&#xA;&lt;p&gt;In Kafka Core:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Kafka Core partition moves: &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Consumer-A loses Partition-0 &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── Consumer-B gets Partition-0 &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── just starts polling from offset ← trivial&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In Kafka Streams, the new task owner also needs to restore state:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Kafka Streams partition moves: &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Consumer-A loses Partition-0 &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── RocksDB state stays on Consumer-A&amp;#39;s disk &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── Consumer-B gets Partition-0 &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── has no local RocksDB state &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── must rebuild from changelog topic ← expensive&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Partition assignment is just metadata in the broker. The state store is actual data on disk. When a rebalance happens, the partition assignment is fast: it is just a metadata update. But the new owner may not have the state locally, so it must replay the changelog to rebuild it.&lt;/p&gt;&#xA;&lt;p&gt;In practice, eliminating or limiting changelog replay is the goal. How? Keep reading.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-to-limit-unnecessary-rebalancing&#34;&gt;How to limit unnecessary rebalancing?&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;cooperative-rebalancing-and-static-membership&#34;&gt;Cooperative Rebalancing and Static Membership&lt;/h3&gt;&#xA;&lt;p&gt;Before cooperative rebalancing, stop-the-world froze ALL partitions during a rebalance. With cooperative rebalancing (KIP-429), only the partitions that need to move are paused.&lt;/p&gt;&#xA;&lt;p&gt;Cooperative rebalancing changes HOW partitions are reassigned DURING a rebalance.&lt;/p&gt;&#xA;&lt;p&gt;Static membership (KIP-345) operates one level earlier: it changes WHETHER a rebalance happens at all. If a pod restarts briefly, does anything need to change?&lt;/p&gt;&#xA;&lt;p&gt;These two mechanisms are complementary. Together they minimize partition movement in the cluster, reducing disruption for any application using it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;session.timeout.ms&lt;/code&gt; controls how long the cluster waits before declaring a member dead.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;static-membership-in-kafka-streams&#34;&gt;Static Membership in Kafka Streams&lt;/h3&gt;&#xA;&lt;p&gt;With very large state, rebalancing often means downtime. Enable static membership with an appropriate timeout to limit it. Static membership and cooperative rebalancing matter more in Kafka Streams than in Kafka Core, because state physically lives on each node.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;sticky-assignor&#34;&gt;Sticky Assignor&lt;/h3&gt;&#xA;&lt;p&gt;The &lt;code&gt;StickyAssignor&lt;/code&gt; has existed since Kafka 0.11: instead of reshuffling all assignments blindly, it preserves existing ones and only moves what is necessary. Kafka 2.4 went further and introduced the &lt;code&gt;CooperativeStickyAssignor&lt;/code&gt;, combining stickiness with cooperative rebalancing. That combination became the default from Kafka 3.1.&lt;/p&gt;&#xA;&lt;p&gt;This is important for Kafka Streams: it keeps state stores on the nodes that already have the data.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;persistent-volumes-kubernetes&#34;&gt;Persistent Volumes (Kubernetes)&lt;/h3&gt;&#xA;&lt;p&gt;By default, data stored in a Kubernetes pod lives on the pod&amp;rsquo;s disk. When the pod is deleted, the data is gone. Persistent Volumes solve this. A PV is storage that lives independently of any pod. A pod requests disk by creating a Persistent Volume Claim (PVC): &amp;ldquo;I need 20 GB, fast SSD, read/write&amp;rdquo;.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;statefulset-identity&#34;&gt;StatefulSet Identity&lt;/h3&gt;&#xA;&lt;p&gt;In Kubernetes, there are two types of workload controllers: Deployments and StatefulSets. The difference is that StatefulSets give each pod a stable identifier:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- `stream-processor-0`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- `stream-processor-1`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- `stream-processor-2`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;- `stream-processor-3`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A StatefulSet with PVC works like Kafka&amp;rsquo;s sticky assignor: each pod with the same ID always gets the same PVC:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Pod `stream-processor-0` will always mount PVC `data-stream-processor-0`&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When a pod restarts, Kubernetes deletes and recreates it with the same name, and reattaches the same PVC.&lt;/p&gt;&#xA;&lt;p&gt;This is another element that limits rebalancing in Kafka Streams.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;standby-replicas&#34;&gt;Standby Replicas&lt;/h3&gt;&#xA;&lt;p&gt;With the Sticky Assignor, Cooperative Rebalancing, and Static Membership, unnecessary rebalancing is limited. StatefulSet and PVC ensure predictable restarts: the same PVC always goes to the same pod. The static membership timeout gives Kubernetes time to finish before Kafka declares a member dead.&lt;/p&gt;&#xA;&lt;p&gt;But what if the timeout is not enough? What if Kubernetes does not finish before the timeout expires?&lt;/p&gt;&#xA;&lt;p&gt;Kafka will treat this as a consumer leave event and trigger rebalancing. It removes the dead member from the group and redistributes its partitions to the remaining consumers. When the pod eventually becomes healthy and rejoins, a second rebalance is triggered. With a large state store, these two rebalances can lead to downtime while the changelog is replayed.&lt;/p&gt;&#xA;&lt;p&gt;To guard against this without adding complexity, Kafka Streams has Standby Replicas.&lt;/p&gt;&#xA;&lt;p&gt;Standby Replicas are a Kafka Streams concept. They are controlled by &lt;code&gt;num.standby.replicas&lt;/code&gt; and work like this:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Assign an active task and a standby task based on &lt;code&gt;num.standby.replicas&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Only the active task processes data. The standby replays the changelog to keep its state current.&lt;/li&gt;&#xA;&lt;li&gt;With &lt;code&gt;num.standby.replicas=1&lt;/code&gt;, you always have one active copy and one standby copy on a different node. This requires at least 2 running application instances; with only one, Kafka Streams silently skips creating the standby.&lt;/li&gt;&#xA;&lt;li&gt;When a node leaves the cluster, another node already has a hot copy of the data.&lt;/li&gt;&#xA;&lt;li&gt;The leave event triggers failover. Instead of replaying the full changelog, the standby only needs to catch up on changes since its last sync.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Standby replicas provide fast failover when something goes wrong in the Kubernetes cluster.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;tldr&#34;&gt;TL;DR&lt;/h2&gt;&#xA;&lt;p&gt;Five configuration decisions that keep stateful Kafka Streams stable on Kubernetes:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Static membership&lt;/strong&gt; (&lt;code&gt;group.instance.id&lt;/code&gt; + &lt;code&gt;session.timeout.ms&lt;/code&gt;) — prevents rebalancing on brief pod restarts. Set the timeout to cover your worst-case rolling update duration.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Cooperative rebalancing&lt;/strong&gt; — pauses only the partitions that need to move, not all of them. Enabled by default from Kafka 3.1; enable explicitly on older versions.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Sticky assignor&lt;/strong&gt; — preserves existing partition assignments during rebalancing, keeping state stores on the nodes that already hold the data. Default from Kafka 3.x.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;StatefulSet + Persistent Volumes&lt;/strong&gt; — gives each pod a stable identity and reattaches the same PVC on restart, so RocksDB state survives pod deletion without changelog replay.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Standby replicas&lt;/strong&gt; (&lt;code&gt;num.standby.replicas&lt;/code&gt;) — keeps a hot copy of state on a second node. If the primary fails after the session timeout expires, failover skips a full changelog replay and catches up from the last sync point only.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>How AI is misused in software teams</title>
      <link>https://lukastymo.com/posts/027-how-ai-is-misused-in-software-teams/</link>
      <pubDate>Wed, 18 Mar 2026 14:58:02 +0000</pubDate>
      <guid>https://lukastymo.com/posts/027-how-ai-is-misused-in-software-teams/</guid>
      <description>&lt;p&gt;AI is making one part of engineering cheaper: producing text and code.&lt;/p&gt;&#xA;&lt;p&gt;The misuse is assuming that cheap output produces progress.&lt;/p&gt;&#xA;&lt;p&gt;Often it produces the opposite: teams generate more artefacts, spend more time validating them, and still do not make better decisions. Noise rises. Coherence falls. The bottleneck shifts from writing to judgment.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;p&gt;AI is making one part of engineering cheaper: producing text and code.&lt;/p&gt;&#xA;&lt;p&gt;The misuse is assuming that cheap output produces progress.&lt;/p&gt;&#xA;&lt;p&gt;Often it produces the opposite: teams generate more artefacts, spend more time validating them, and still do not make better decisions. Noise rises. Coherence falls. The bottleneck shifts from writing to judgment.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-core-pattern-output-inflation&#34;&gt;The core pattern: output inflation&lt;/h2&gt;&#xA;&lt;p&gt;When creation becomes cheap, organisations create more:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;stories instead of tickets&lt;/li&gt;&#xA;&lt;li&gt;documents instead of decisions&lt;/li&gt;&#xA;&lt;li&gt;dashboards instead of understanding&lt;/li&gt;&#xA;&lt;li&gt;PR text instead of reviewable intent&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The visible activity looks like productivity, but the system does not improve because the underlying question is unanswered: &lt;em&gt;what are we trying to achieve, and what constraints matter?&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;AI can format an Agile story, generate sequence diagrams, and expand a rough idea into 30 pages. If the goal is unclear, the result is a polished version of confusion.&lt;/p&gt;&#xA;&lt;p&gt;The symptom is familiar: delivery still feels slow, and the team now has an additional burden—reading, verifying, and maintaining more material than before.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;ai-does-not-replace-judgment&#34;&gt;AI does not replace judgment&lt;/h2&gt;&#xA;&lt;p&gt;Some people treat this as a prompting problem: “we just need longer, better prompts.”&lt;/p&gt;&#xA;&lt;p&gt;That misunderstands how software is built. Good engineering is iterative:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;you learn as you go&lt;/li&gt;&#xA;&lt;li&gt;you discover unknowns by trying things&lt;/li&gt;&#xA;&lt;li&gt;you refactor when the design stops fitting&lt;/li&gt;&#xA;&lt;li&gt;you stop features that aren’t worth the complexity&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;That loop is a judgment loop. It depends on context, trade-offs, and the ability to say “no.”&lt;/p&gt;&#xA;&lt;p&gt;AI can help within the loop, but it cannot replace it.&lt;/p&gt;&#xA;&lt;p&gt;Output inflation also delays the moment when the system forces a decision. You can ship more generated code and more generated documentation and feel like progress is happening—until maintenance debt becomes undeniable.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-dashboard-trap-mcp-and-automation&#34;&gt;The dashboard trap (MCP and automation)&lt;/h2&gt;&#xA;&lt;p&gt;MCP and similar tooling can scaffold dashboards and automate tedious work. The trap is that it makes producing dashboards easy, without making the monitoring system useful.&lt;/p&gt;&#xA;&lt;p&gt;You end up with:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;100 dashboards nobody owns&lt;/li&gt;&#xA;&lt;li&gt;10 versions of the same Kafka lag panel&lt;/li&gt;&#xA;&lt;li&gt;anomaly detection that looks impressive but answers the wrong questions&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;During an incident, the team still lacks the few charts that matter because those are usually built iteratively, in response to real failures and changing systems. Monitoring is not a deliverable. It is a living system.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-pr-description-trap&#34;&gt;The PR description trap&lt;/h2&gt;&#xA;&lt;p&gt;Code review quality does not automatically improve with AI. Often it gets worse.&lt;/p&gt;&#xA;&lt;p&gt;Instead of a short human summary of intent (“what changed, why, what to watch for”), reviews get flooded with AI-generated descriptions that are long, generic, and low-signal.&lt;/p&gt;&#xA;&lt;p&gt;The effect is predictable:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;reviewers stop reading&lt;/li&gt;&#xA;&lt;li&gt;false alarms increase&lt;/li&gt;&#xA;&lt;li&gt;teams learn to ignore the text&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;It is another case where the organisation gets more output and less clarity.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-security-trap&#34;&gt;The security trap&lt;/h2&gt;&#xA;&lt;p&gt;Security can degrade when teams treat AI as a magic upgrade.&lt;/p&gt;&#xA;&lt;p&gt;In practice this shows up as:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;overly broad permissions (“just give it access, it will be fine”)&lt;/li&gt;&#xA;&lt;li&gt;production access that bypasses normal review and controls&lt;/li&gt;&#xA;&lt;li&gt;uncontrolled automation that turns mistakes into incidents&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;If AI helps you deliver better outcomes with less risk, it is a win. If it creates shiny pipelines while increasing risk and reducing accountability, it is a loss.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;vibe-coding-good-at-the-start-fragile-later&#34;&gt;Vibe coding: good at the start, fragile later&lt;/h2&gt;&#xA;&lt;p&gt;Vibe coding can be excellent for scaffolding and getting to a first version quickly. The failure mode appears when the system grows:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;prompts expand&lt;/li&gt;&#xA;&lt;li&gt;coupling grows&lt;/li&gt;&#xA;&lt;li&gt;changes become risky&lt;/li&gt;&#xA;&lt;li&gt;the only way to move is “ask the model again”&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;At that point you are not delegating typing. You are delegating thinking. The system becomes harder to simplify because the simplification work is the very thing you outsourced.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-subtle-shift-writing-becomes-reading&#34;&gt;The subtle shift: writing becomes reading&lt;/h2&gt;&#xA;&lt;p&gt;A common argument is “we review what the model produces.”&lt;/p&gt;&#xA;&lt;p&gt;But that can flip the economics. Writing code was often the faster part. Understanding a large volume of generated output can be slower. Some teams even reduce or skip review because generation is fast. That is the most dangerous version: speed without control.&lt;/p&gt;&#xA;&lt;p&gt;The real question is not “can we generate more?” It is “are we improving outcomes per unit of attention?”&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;where-ai-actually-compounds&#34;&gt;Where AI actually compounds&lt;/h2&gt;&#xA;&lt;figure class=&#34;not-prose my-8&#34;&gt;&#xA;  &lt;img src=&#34;https://lukastymo.com/images/posts/027/michael-soledad-9juYjd6iQLU-unsplash.jpg&#34; alt=&#34;Black keyboard on desk&#34; class=&#34;w-full h-auto&#34; /&gt;&#xA;  &lt;figcaption class=&#34;mt-2 text-sm text-gray-500 dark:text-gray-400 text-left font-sans&#34;&gt;Photo by &lt;a href=&#34;https://unsplash.com/@michsole?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText&#34;&gt;Michael Soledad&lt;/a&gt; on &lt;a href=&#34;https://unsplash.com/photos/black-keyboard-on-desk-9juYjd6iQLU?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText&#34;&gt;Unsplash&lt;/a&gt;&lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;p&gt;AI compounds when it strengthens judgment and reduces entropy:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;turning messy context into a crisp problem statement&lt;/li&gt;&#xA;&lt;li&gt;generating trade-offs and failure modes before a decision&lt;/li&gt;&#xA;&lt;li&gt;producing review checklists that force explicit intent&lt;/li&gt;&#xA;&lt;li&gt;summarising incidents into concrete lessons and monitoring changes&lt;/li&gt;&#xA;&lt;li&gt;tightening scope and constraints before implementation&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;These uses create leverage because they improve decisions and coordination. They reduce the noise you need to maintain.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;a-forward-looking-consequence-data-work-becomes-more-valuable&#34;&gt;A forward-looking consequence: data work becomes more valuable&lt;/h2&gt;&#xA;&lt;p&gt;As information becomes cheaper to produce, the volume of data and text will grow. The scarce capability becomes filtering, cleaning, structuring, and making it usable.&lt;/p&gt;&#xA;&lt;p&gt;That suggests data engineering and data-quality practice will matter more, not less—not only in companies, but in personal knowledge systems too.&lt;/p&gt;&#xA;&lt;p&gt;The future is not “replace humans with markdown files.” It is “use AI to reduce entropy while humans make the decisions.”&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>AI Will Not Replace Developers - It Will Make Them More Necessary Than Ever</title>
      <link>https://lukastymo.com/posts/026-ai-will-never-replace-developers/</link>
      <pubDate>Wed, 11 Mar 2026 22:27:43 +0000</pubDate>
      <guid>https://lukastymo.com/posts/026-ai-will-never-replace-developers/</guid>
      <description>&lt;p&gt;For the past few years, a familiar narrative has been circulating through the technology industry: artificial&#xA;intelligence will soon replace software developers. Each new model release fuels another round of predictions that&#xA;coding will become obsolete.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;For the past few years, a familiar narrative has been circulating through the technology industry: artificial&#xA;intelligence will soon replace software developers. Each new model release fuels another round of predictions that&#xA;coding will become obsolete.&lt;/p&gt;&#xA;&lt;p&gt;But this argument misunderstands what good developers actually do.&lt;/p&gt;&#xA;&lt;p&gt;Programming was never primarily about writing code. In practice, it is often only a small fraction of a developer’s time.&lt;/p&gt;&#xA;&lt;p&gt;The real value of a developer lies in understanding&#xA;&lt;em&gt;what should be built&lt;/em&gt; - and, just as importantly, what should &lt;strong&gt;not be built&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-real-job-of-a-developer&#34;&gt;The Real Job of a Developer&lt;/h2&gt;&#xA;&lt;p&gt;A strong developer does three things exceptionally well:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Understands the problem&lt;/strong&gt; the business is actually trying to solve.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Applies experience and best practices&lt;/strong&gt; gathered over years of building systems.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Reduces system entropy&lt;/strong&gt; by decoupling components and maintaining architectural clarity.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Writing code is simply the visible by-product of these activities.&lt;/p&gt;&#xA;&lt;p&gt;Good engineers spend far more time thinking about structure, constraints, and trade-offs than they do typing.&lt;/p&gt;&#xA;&lt;p&gt;AI does not change this reality.&lt;/p&gt;&#xA;&lt;p&gt;If anything, it amplifies it.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;from-10-developers-to-100&#34;&gt;From 10× Developers to 100×&lt;/h2&gt;&#xA;&lt;p&gt;For decades the industry has talked about “10× developers” - individuals whose productivity far exceeds the average.&lt;/p&gt;&#xA;&lt;p&gt;AI tools promise to make everyone faster. Code can now be generated almost instantly, boilerplate disappears, and entire&#xA;components appear after a prompt.&lt;/p&gt;&#xA;&lt;p&gt;But this raises the bar rather than lowering it.&lt;/p&gt;&#xA;&lt;p&gt;If everyone can generate code easily, the differentiator becomes &lt;strong&gt;judgment&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Developers who were once considered 10× are now expected to become 100× - architects of systems and decisions rather than mere producers of code.&lt;/p&gt;&#xA;&lt;p&gt;Yet the original notion of the 10× developer also included leadership and mentoring. The best engineers multiplied the effectiveness of the people around them.&lt;/p&gt;&#xA;&lt;p&gt;In the race for 100× productivity, however, it is easy to spend more time pairing with Claude or other GPTs than with fellow developers.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-first-problem-the-organisational-bottleneck&#34;&gt;The First Problem: The Organisational Bottleneck&lt;/h2&gt;&#xA;&lt;p&gt;AI dramatically improves the &lt;em&gt;vertical&lt;/em&gt; part of development: producing code.&lt;/p&gt;&#xA;&lt;p&gt;But code generation is only one stage of the software pipeline.&lt;/p&gt;&#xA;&lt;p&gt;Organisations still need:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;product direction&lt;/li&gt;&#xA;&lt;li&gt;architectural alignment&lt;/li&gt;&#xA;&lt;li&gt;testing&lt;/li&gt;&#xA;&lt;li&gt;deployment pipelines&lt;/li&gt;&#xA;&lt;li&gt;operational monitoring&lt;/li&gt;&#xA;&lt;li&gt;cross-team coordination&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Improving only the coding step does not automatically improve the entire system.&lt;/p&gt;&#xA;&lt;p&gt;To truly benefit from AI, organisations must restructure their processes end-to-end.&lt;/p&gt;&#xA;&lt;p&gt;This is not a small change. It resembles the transition to remote work during Covid-19, but may be more difficult.&lt;/p&gt;&#xA;&lt;p&gt;It requires new workflows, new documentation habits, new coordination models, and new security practices.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-second-problem-the-explosion-of-artifacts&#34;&gt;The Second Problem: The Explosion of Artifacts&lt;/h2&gt;&#xA;&lt;p&gt;The more subtle challenge is that AI makes creation almost free.&lt;/p&gt;&#xA;&lt;p&gt;When something is free, people create more of it.&lt;/p&gt;&#xA;&lt;p&gt;Suddenly we have:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;not documentation, but comprehensive documentation&lt;/li&gt;&#xA;&lt;li&gt;not one architecture diagram, but hundreds of diagrams&lt;/li&gt;&#xA;&lt;li&gt;not one dashboard, but dozens of dashboards&lt;/li&gt;&#xA;&lt;li&gt;not one design proposal, but pages of LLM-generated analysis&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;And perhaps most dangerously:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;not a story with just a title - an honest signal that we still need to investigate - but hidden unknowns buried under layers of generated generalisations and hallucinations.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;None of this necessarily increases ROI.&lt;/p&gt;&#xA;&lt;p&gt;Instead, teams must now &lt;strong&gt;read and process enormous volumes of AI-generated material&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Code reviews become longer. Documentation grows thicker. Architectural discussions become noisier.&lt;/p&gt;&#xA;&lt;p&gt;Ironically, developers become busier, not less.&lt;/p&gt;&#xA;&lt;p&gt;Anyone who has experimented with vibe coding knows the pattern. At first everything feels fast and smooth. Code appears instantly, ideas flow, and progress seems effortless. Then a &lt;strong&gt;critical moment&lt;/strong&gt; arrives: the prompts grow longer, the models consume more tokens, responses slow down, and the results begin to deteriorate.&lt;/p&gt;&#xA;&lt;p&gt;The same dynamic can emerge at the organisational level in so-called “AI-native companies”. Remove too much human judgment and you also remove the person who can recognise when a system is becoming &lt;strong&gt;unnecessarily complex&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Large language models rarely challenge the premise of a request. They optimise for answering the prompt. If they lack certainty, they will often still produce a confident guess - a behaviour shaped by reinforcement learning, which rewards responses that appear helpful and decisive.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-feature-creep-problem&#34;&gt;The Feature Creep Problem&lt;/h2&gt;&#xA;&lt;p&gt;Historically, one of the most valuable roles of a developer was saying &lt;strong&gt;no&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Good engineers constantly negotiate with the business:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;identifying what users actually need&lt;/li&gt;&#xA;&lt;li&gt;removing unnecessary complexity&lt;/li&gt;&#xA;&lt;li&gt;preventing tightly coupled systems&lt;/li&gt;&#xA;&lt;li&gt;stopping feature creep before it begins&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;AI changes the psychology of software development.&lt;/p&gt;&#xA;&lt;p&gt;Because implementation suddenly appears easy, everything seems possible.&lt;/p&gt;&#xA;&lt;p&gt;And when everything is possible, systems grow uncontrollably.&lt;/p&gt;&#xA;&lt;p&gt;Features accumulate. Complexity increases. Coupling spreads across services.&lt;/p&gt;&#xA;&lt;p&gt;No prompt can reliably stop this process.&lt;/p&gt;&#xA;&lt;p&gt;Only humans can.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-value-of-imperfect-intelligence&#34;&gt;The Value of Imperfect Intelligence&lt;/h2&gt;&#xA;&lt;p&gt;Ironically, the strength of human developers is precisely that we are imperfect.&lt;/p&gt;&#xA;&lt;p&gt;With limited attention and cognitive capacity, good engineers instinctively simplify.&lt;/p&gt;&#xA;&lt;p&gt;They ask questions like:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Do we really need this feature?&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Can we remove this dependency?&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;What happens to the system in three years if we build this?&lt;/em&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;AI optimises for generating possibilities.&lt;/p&gt;&#xA;&lt;p&gt;Humans optimise for reducing them.&lt;/p&gt;&#xA;&lt;p&gt;That filtering function will remain essential.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;smaller-teams-not-no-teams&#34;&gt;Smaller Teams, Not No Teams&lt;/h2&gt;&#xA;&lt;p&gt;The clickbait prediction that “AI will replace developers” is unlikely to happen.&lt;/p&gt;&#xA;&lt;p&gt;A more realistic outcome is &lt;strong&gt;smaller, more powerful teams&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This has happened before.&lt;/p&gt;&#xA;&lt;p&gt;Software development has repeatedly evolved:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Assembly → High-level languages&lt;/li&gt;&#xA;&lt;li&gt;Waterfall → Agile&lt;/li&gt;&#xA;&lt;li&gt;Monoliths → Distributed systems&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Each transition changed how teams work.&lt;/p&gt;&#xA;&lt;p&gt;AI is simply another shift.&lt;/p&gt;&#xA;&lt;p&gt;But instead of eliminating developers, it changes their role.&lt;/p&gt;&#xA;&lt;p&gt;Developers are moving further up the abstraction ladder - from writing code to designing systems.&lt;/p&gt;&#xA;&lt;p&gt;In earlier generations of software tooling, discipline meant writing tests. In the age of AI-assisted development, it means controlling coupling and complexity.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-conditions-for-the-next-generation-of-teams&#34;&gt;The Conditions for the Next Generation of Teams&lt;/h2&gt;&#xA;&lt;p&gt;For AI-augmented development teams to reach their full potential, two things must happen.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;1-strong-human-architects&#34;&gt;1. Strong Human Architects&lt;/h3&gt;&#xA;&lt;p&gt;Teams will need talented individuals who can keep systems predictable even when using probabilistic tools like LLMs.&lt;/p&gt;&#xA;&lt;p&gt;These developers must:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;manage complexity&lt;/li&gt;&#xA;&lt;li&gt;enforce architectural boundaries&lt;/li&gt;&#xA;&lt;li&gt;filter ideas before they reach production&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;In other words, they must guide the system through &lt;strong&gt;intentional constraint&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;2-organisations-must-centralise-knowledge&#34;&gt;2. Organisations Must Centralise Knowledge&lt;/h3&gt;&#xA;&lt;p&gt;AI works best when knowledge is structured.&lt;/p&gt;&#xA;&lt;p&gt;Organisations will increasingly move towards &lt;strong&gt;processes defined in files&lt;/strong&gt; - ideally simple formats like Markdown.&lt;/p&gt;&#xA;&lt;p&gt;Architecture decisions, workflows, product reasoning, and operational knowledge will need to live in clear, searchable&#xA;systems.&lt;/p&gt;&#xA;&lt;p&gt;In effect, companies will need organisational “knowledge operating systems”. Tools like Obsidian are more important&#xA;than ever.&lt;/p&gt;&#xA;&lt;p&gt;In the cloud shift, Terraform and infrastructure as code (IaC) emerged. Similarly, in the AI era, something like &lt;strong&gt;Company as Code&lt;/strong&gt; will inevitably emerge.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-return-of-old-ideas&#34;&gt;The Return of Old Ideas&lt;/h2&gt;&#xA;&lt;p&gt;Interestingly, many older knowledge-management methods may become even more popular.&lt;/p&gt;&#xA;&lt;p&gt;Systems such as:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Zettelkasten&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Second Brain&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;structured personal knowledge bases&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;may become central to how developers work with AI.&lt;/p&gt;&#xA;&lt;p&gt;The development process itself may also evolve into a hybrid of Agile and Waterfall: iterative experimentation supported&#xA;by strong documentation.&lt;/p&gt;&#xA;&lt;p&gt;LLMs thrive on written context.&lt;/p&gt;&#xA;&lt;p&gt;The more structured that context becomes, the more powerful the collaboration between humans and machines will be.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-real-future-of-development&#34;&gt;The Real Future of Development&lt;/h2&gt;&#xA;&lt;p&gt;AI will dramatically change software engineering.&lt;/p&gt;&#xA;&lt;p&gt;But not in the way many expect.&lt;/p&gt;&#xA;&lt;p&gt;The future developer is not someone whose job is only prompting models to generate code.&lt;/p&gt;&#xA;&lt;p&gt;It is a &lt;strong&gt;systems thinker managing complexity in a world where creation is cheap but clarity is rare&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;And as long as software systems remain complex - and businesses remain uncertain - developers will remain essential.&lt;/p&gt;&#xA;&lt;p&gt;Possibly more than ever.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Hello, Haskell: Getting Started in 2026</title>
      <link>https://lukastymo.com/posts/025-hello-haskell-a-hands-on-lab-for-2026/</link>
      <pubDate>Sun, 25 Jan 2026 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/025-hello-haskell-a-hands-on-lab-for-2026/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Read this if you want to:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;see beginner examples that link Haskell’s syntax to its underlying mental models – types, pattern matching, declarative style and &lt;code&gt;do&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;see examples of Haskell’s distinctive syntax in practice&lt;/li&gt;&#xA;&lt;li&gt;learn what Robin Milner’s work changed in functional programming&lt;/li&gt;&#xA;&lt;li&gt;write and run code as you go&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;In the current AI era, Rust and Python draw the most attention from learners and employers. Haskell, by contrast, remains niche: it trends lower on Google Trends and has far fewer job listings on LinkedIn. When roles do appear, the bar can be high enough that newcomers struggle to get started.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;&lt;strong&gt;Read this if you want to:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;see beginner examples that link Haskell’s syntax to its underlying mental models – types, pattern matching, declarative style and &lt;code&gt;do&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;see examples of Haskell’s distinctive syntax in practice&lt;/li&gt;&#xA;&lt;li&gt;learn what Robin Milner’s work changed in functional programming&lt;/li&gt;&#xA;&lt;li&gt;write and run code as you go&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;In the current AI era, Rust and Python draw the most attention from learners and employers. Haskell, by contrast, remains niche: it trends lower on Google Trends and has far fewer job listings on LinkedIn. When roles do appear, the bar can be high enough that newcomers struggle to get started.&lt;/p&gt;&#xA;&lt;p&gt;Meanwhile, LLMs now write a growing share of code, and developers are unusually uncertain about the profession’s direction. Interest in functional programming has also cooled since 2022 across employers and employees. The pragmatic objection recurs: strong FP developers are scarce, and their rates often do not look justified for the work being built.&lt;/p&gt;&#xA;&lt;p&gt;Against that backdrop, hype is a poor guide. Learning tends to last longer when it is driven by intellectual interest rather than short-term demand. Haskell suits readers drawn to type-driven design and compact, algebraic notation.&lt;/p&gt;&#xA;&lt;p&gt;A common observation is that a language may appear strange at first; once learned, other languages can begin to look unfamiliar. The same pattern appears when learning ideas such as type classes and tagless final in Scala: explanations often fail to “click” when the original context has been stripped away. Much of this material was imported from Haskell, adapted with trade-offs and additions, and then presented in isolation; returning to the source often clarifies what the abstraction is doing.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-slate-200 bg-slate-50 dark:border-slate-600 dark:bg-slate-800 text-slate-800 dark:text-slate-200 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ✅&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Hands-on approach&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;A hands-on approach works best. These examples work best when they are typed into an editor and executed, so their behavior is visible directly.&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&#xA;&lt;h2 id=&#34;setting-the-foundations&#34;&gt;Setting the foundations&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;tooling-and-workspace&#34;&gt;Tooling and workspace&lt;/h3&gt;&#xA;&lt;p&gt;Haskell is often approached a few times over the years. In 2026, the basic setup is clear enough to reduce churn, but tooling still decides whether time goes into learning the language or debugging editors.&lt;/p&gt;&#xA;&lt;p&gt;JetBrains IDEs are often the default for consistent shortcuts and workflow. That works well for Scala in IntelliJ, Python in PyCharm, C++ in CLion, and React/JS in WebStorm. For Haskell, however, there is no comparable “it just works” experience: the plugins evaluated were either obsolete or unreliable, and time can be lost to tooling rather than to concepts.&lt;/p&gt;&#xA;&lt;p&gt;By contrast, VS Code with a Haskell extension is a reliable default. Shortcuts are discoverable via the Command Palette; the UI shows each command’s shortcut. A dedicated learning repository helps isolate experiments. A common pattern is &lt;code&gt;sandbox-&amp;lt;language-name&amp;gt;&lt;/code&gt;, for example &lt;code&gt;sandbox-haskell&lt;/code&gt;, kept private to reduce the risk of accidental disclosure.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;organizing-practice&#34;&gt;Organizing practice&lt;/h3&gt;&#xA;&lt;p&gt;The folder structure used here is:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;tree -L 2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├── README.md&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├── src&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── Books (1)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── codeforces&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── euler&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── finalprojects&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── goals&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── h99&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   ├── spoj&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;│   └── Wiki (2)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├── stack.yaml&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;├── stack.yaml.lock&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── test&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └── Spec.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The structure separates &lt;code&gt;src/Books&lt;/code&gt; and &lt;code&gt;src/Wiki&lt;/code&gt; to support two loops: working through books and maintaining a personal reference.&lt;/p&gt;&#xA;&lt;p&gt;Book exercises are typically organised as:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; tree -L 2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;└── ProgrammingInHaskell&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── Ch01.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── Ch02.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    ├── Ch04.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └── Ch05.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A wiki reference is typically organised as:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; Algorithms&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    └── Sort.hs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Haskell syntax is close to mathematical notation, so some algorithms end up looking notably close to pseudocode. The wiki can serve as a reference: “What does idiomatic Haskell look like?” Over time it reduces the cost of relearning details and limits exposure to low-quality patterns from LLMs.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;installing-the-toolchain&#34;&gt;Installing the toolchain&lt;/h3&gt;&#xA;&lt;p&gt;Installation is OS-specific. On Fedora, the setup was:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;gmp-devel&lt;/code&gt; provides the headers for the GMP library, which GHC and many packages rely on for efficient big-integer arithmetic.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; sudo dnf install gmp-devel&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;GHCup is the de facto toolchain installer/manager for Haskell: it can install and switch between versions of GHC, Cabal, Stack, and HLS.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;curl --proto &amp;#39;=https&amp;#39; --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The compiler version used here is 9.8.4.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ghcup install ghc 9.8.4&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ghcup set ghc 9.8.4&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A first Haskell file typically uses the &lt;code&gt;.hs&lt;/code&gt; extension. The examples below use &lt;code&gt;./src/Hello.hs&lt;/code&gt;, opened in VS Code to enable editor feedback and type hints.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;ai-as-an-auxiliary-tool&#34;&gt;AI as an auxiliary tool&lt;/h2&gt;&#xA;&lt;p&gt;Copilot is generally better to avoid at this point: it reduces active thinking and slows the formation of a mental model.&lt;/p&gt;&#xA;&lt;p&gt;LLMs are most useful as a secondary tool for troubleshooting tooling, installation, and confusing error messages.&lt;/p&gt;&#xA;&lt;p&gt;After solving an exercise, comparing it with an LLM solution can also be useful.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2 id=&#34;first-steps-in-ghci&#34;&gt;First steps in GHCi&lt;/h2&gt;&#xA;&lt;p&gt;With a Haskell extension in VS Code and GHC installed, a minimal module is enough to confirm that the toolchain works end to end. Early on, keeping examples in a single file and loading them via &lt;code&gt;ghci&lt;/code&gt; lets you iterate quickly without a full build.&lt;/p&gt;&#xA;&lt;p&gt;GHCi is Haskell&amp;rsquo;s interactive REPL: it loads modules, type-checks and evaluates expressions, and supports fast iteration. For example:&lt;/p&gt;&#xA;&lt;p&gt;./src/Hello.hs:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;add x y = x + y&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A typical session starts from the &lt;code&gt;src&lt;/code&gt; directory:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;cd src&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;ghci&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once GHCi starts, the file is loaded:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-gdscript3&#34; data-lang=&#34;gdscript3&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;load&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Hello&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hs&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Shorthand: &lt;code&gt;:l Hello.hs&lt;/code&gt;. After loading the file, the &lt;code&gt;add&lt;/code&gt; function is available. After editing the file, it is reloaded with:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-gdscript3&#34; data-lang=&#34;gdscript3&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;reload&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or the shorthand &lt;code&gt;:r&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The function can then be called by name:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;add 1 2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: 3&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;verifying-the-setup&#34;&gt;Verifying the setup&lt;/h3&gt;&#xA;&lt;p&gt;A short sanity check that the environment is wired correctly:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;ghci&lt;/code&gt; runs in the &lt;code&gt;src&lt;/code&gt; directory&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;:load Hello.hs&lt;/code&gt; loads the file&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;add 1 2&lt;/code&gt; returns &lt;code&gt;3&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;types-as-the-surface-of-programs&#34;&gt;Types as the surface of programs&lt;/h2&gt;&#xA;&lt;p&gt;In Haskell, everything is expressed in terms of values and functions. There’s no mutation in the “update a variable” sense, which is what people mean when they call Haskell a &lt;em&gt;pure&lt;/em&gt; functional language. By contrast, in a multi-paradigm language like Scala, it’s possible to write &lt;code&gt;var x = 5&lt;/code&gt; and later update it to &lt;code&gt;x = 6&lt;/code&gt;. That style is not how Haskell code is structured, and it changes how programs are reasoned about.&lt;/p&gt;&#xA;&lt;p&gt;A second function helps clarify terminology. The distinction between “method” and “function” matters in Haskell’s model.&lt;/p&gt;&#xA;&lt;p&gt;In Haskell, an expression such as &lt;code&gt;add x y = x + y&lt;/code&gt; defines a pure function. It is a function rather than a method because it does not belong to a class or an object: there is no implicit receiver (this) and no dot-syntax. It is simply a mapping from inputs to an output.&lt;/p&gt;&#xA;&lt;p&gt;The function is pure because it has no side effects and is deterministic: for the same inputs, it always produces the same result. This property allows the expression to be reasoned about mathematically and makes its behaviour predictable and testable.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;“Methods” do exist in Haskell&lt;/strong&gt;, but they’re tied to &lt;em&gt;type classes&lt;/em&gt;, roughly corresponding to Scala typeclasses. That is a different mental model than object-oriented methods. These examples use plain functions:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;double&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This function doubles its input. No types are written here because languages in the ML family introduced &lt;strong&gt;type inference&lt;/strong&gt;. Robin Milner and others introduced type inference in the 1970s, and the compiler can often infer types automatically. Counterintuitively, the result is concise code without giving up static guarantees.&lt;/p&gt;&#xA;&lt;p&gt;To define types, Haskell uses the &lt;code&gt;::&lt;/code&gt; syntax:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;double&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;::&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;double&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Repeating the name – once for the type signature and once for the definition – can look “anti-DRY”. In practice, it separates the declaration from the implementation and makes the code easier to reason about. It also keeps the abstract level of types separate from implementation details.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-slate-200 bg-slate-50 dark:border-slate-600 dark:bg-slate-800 text-slate-800 dark:text-slate-200 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ℹ️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Haskell Fact 1&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;&lt;p&gt;Haskell separates:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;what it is&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;from &lt;strong&gt;how it works&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;From a more mathematical point of view:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the &lt;strong&gt;type signature is a theorem&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;the &lt;strong&gt;function body is a proof&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;From a more mathematical point of view, Haskell treats types like a form of logic: the type signature is a theorem, and the function body is a proof.&lt;/p&gt;&#xA;&lt;p&gt;When should type signatures be written, and when should inference be used?&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-slate-200 bg-slate-50 dark:border-slate-600 dark:bg-slate-800 text-slate-800 dark:text-slate-200 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ✅&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Haskell Rule 1&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;&lt;p&gt;Top-level definitions should have explicit type signatures.&lt;/p&gt;&#xA;&lt;p&gt;Add types:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;if it is a top-level function that will be public in the module&lt;/li&gt;&#xA;&lt;li&gt;if a function is complex, and adding types makes it easier to reason&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Skip types:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;simple helper functions which are called by other main ones&lt;/li&gt;&#xA;&lt;li&gt;for simple helpers, let VS Code generate them via quick fix&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;While learning, types are often omitted initially and generated by the editor. Inferred types can be more general, and more complex, than expected because polymorphism introduces &lt;em&gt;typeclass constraints&lt;/em&gt;. A typeclass constraint is a requirement that a type supports a particular set of operations, such as ordering for sorting.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;expressiveness-as-structure&#34;&gt;Expressiveness as structure&lt;/h3&gt;&#xA;&#xA;&lt;h4 id=&#34;decomposition-with-patterns-and-recursion&#34;&gt;Decomposition with patterns and recursion&lt;/h4&gt;&#xA;&lt;p&gt;Pattern matching is a central readability feature. It is used directly in a function definition and is more capable than in many mainstream languages.&lt;/p&gt;&#xA;&lt;p&gt;For example, here is a function that sums a list:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;mySum&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;[]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;mySum&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ns&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;n&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mySum&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ns&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This definition begins with the base case. When the list is empty, it returns 0.&lt;/p&gt;&#xA;&lt;p&gt;The second clause handles the general case. &lt;strong&gt;Pattern matching&lt;/strong&gt; splits the input into one element &lt;code&gt;n&lt;/code&gt; and the rest of the list &lt;code&gt;ns&lt;/code&gt;, which can still be empty.&lt;/p&gt;&#xA;&lt;p&gt;Function calls don’t require parentheses; the typical form is &lt;code&gt;nameOfFunction arg1 arg2 ...&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In this example, &lt;code&gt;mySum&lt;/code&gt; calls itself – classic &lt;strong&gt;recursion&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A common question is whether this is stack-safe and performant. In general, the naive version is &lt;em&gt;not&lt;/em&gt; stack-safe. However, idiomatic Haskell uses a strict fold like &lt;code&gt;foldl&#39;&lt;/code&gt;, or an explicit accumulator, to avoid building up thunks, or deferred computations. For summing there are built-in helpers already.&lt;/p&gt;&#xA;&lt;p&gt;A rough progression from teaching examples to production code:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;recursion replaces loops&lt;/li&gt;&#xA;&lt;li&gt;but folds replace recursion&lt;/li&gt;&#xA;&lt;li&gt;and strict folds replace naive folds&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h4 id=&#34;declarative-formulations&#34;&gt;Declarative formulations&lt;/h4&gt;&#xA;&lt;p&gt;Declarative style supports reasoning: it describes &lt;em&gt;what&lt;/em&gt; is needed, not &lt;em&gt;how&lt;/em&gt; to do it step-by-step.&lt;/p&gt;&#xA;&lt;p&gt;Quicksort illustrates the declarative style:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;qsort&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;::&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Ord&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (1)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;qsort&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;[]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;[]&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (2)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;qsort&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;xs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;qsort&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;smaller&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;++&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;++&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;qsort&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;larger&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (3)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;kr&#34;&gt;where&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (4)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;smaller&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;xs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;larger&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;xs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol&gt;&#xA;&lt;li&gt;Read the type declaration backwards&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;[a]&lt;/code&gt; - list of elements of type a - a is any type like Int, String, or custom types like Person, and the list contains those values, for example a list of ints&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;[a] -&amp;gt; [a]&lt;/code&gt; - the function expects a list of &lt;code&gt;a&lt;/code&gt; and returns a list of &lt;code&gt;a&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;(Ord a) =&amp;gt;&lt;/code&gt; - we accept any type &lt;code&gt;a&lt;/code&gt;, as long as it has an &lt;code&gt;Ord&lt;/code&gt; instance so we can compare/order values of that type&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;It defines sorting for an empty list (the trivial case)&lt;/li&gt;&#xA;&lt;li&gt;It uses pattern matching to split the list into one element x and the rest (xs)&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This is the part where the algorithm looks like a standard quicksort definition.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Recursion&lt;/strong&gt; sorts the &lt;code&gt;smaller&lt;/code&gt; part, concatenates it with the one-element list &lt;code&gt;[x]&lt;/code&gt;, and then concatenates the sorted &lt;code&gt;larger&lt;/code&gt; part&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;where&lt;/code&gt; defines what is meant by &lt;code&gt;smaller&lt;/code&gt; and &lt;code&gt;larger&lt;/code&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;We use &lt;code&gt;[a | a &amp;lt;- xs, a &amp;lt;= x]&lt;/code&gt;, a list comprehension that looks like mathematical set-builder notation. That’s one reason mathematicians often enjoy Haskell.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Is this faster than C++/Java? Typically not.&lt;/p&gt;&#xA;&lt;p&gt;It is mainly an example of expressive syntax. However, performance-critical operations typically rely on more specialized structures and primitives. Under the hood, &lt;code&gt;[a]&lt;/code&gt; is a linked list, and append is (O(n)), which makes this particular quicksort formulation expensive.&lt;/p&gt;&#xA;&lt;p&gt;Is it possible to implement a fast quicksort in Haskell? Yes – but it requires addressing the bottleneck and using something more appropriate, like &lt;code&gt;Data.Vector&lt;/code&gt; / &lt;code&gt;Data.Array&lt;/code&gt;, or using a well-tested library implementation.&lt;/p&gt;&#xA;&lt;p&gt;This shows a familiar FP trade-off: purity supports reasoning and the modelling of business rules, yet mission-critical performance often requires controlled mutation.&lt;/p&gt;&#xA;&lt;aside class=&#34;not-prose my-6 rounded-md border-l-4 border-slate-200 bg-slate-50 dark:border-slate-600 dark:bg-slate-800 text-slate-800 dark:text-slate-200 px-4 py-3&#34;&gt;&#xA;  &lt;div class=&#34;flex items-start gap-2&#34;&gt;&#xA;    &lt;span class=&#34;mt-[2px] opacity-60 leading-none&#34; aria-hidden=&#34;true&#34;&gt;&#xA;      ℹ️&#xA;    &lt;/span&gt;&#xA;&#xA;    &lt;div class=&#34;space-y-2 text-sm sm:text-base leading-relaxed&#34;&gt;&#xA;      &lt;div class=&#34;flex items-center gap-2 font-semibold&#34;&gt;Haskell Fact 2&lt;/div&gt;&#xA;&#xA;      &lt;div class=&#34;&#xA;        [&amp;&gt;p]:m-0&#xA;        [&amp;&gt;ul]:m-0 [&amp;&gt;ul]:list-disc [&amp;&gt;ul]:pl-5&#xA;        [&amp;&gt;ol]:m-0 [&amp;&gt;ol]:list-decimal [&amp;&gt;ol]:pl-5&#xA;        [&amp;&gt;ul&gt;li]:mt-1 [&amp;&gt;ol&gt;li]:mt-1&#xA;        [&amp;&gt;ul&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;ol&gt;li::marker]:opacity-50&#xA;        [&amp;&gt;pre]:m-0 [&amp;&gt;pre]:overflow-x-auto&#xA;        [&amp;_a]:underline [&amp;_a]:underline-offset-2 [&amp;_a]:font-semibold&#xA;&#34;&gt;Purity outside, mutation inside:&lt;/div&gt;&#xA;    &lt;/div&gt;&#xA;  &lt;/div&gt;&#xA;&lt;/aside&gt;&#xA;&#xA;&lt;p&gt;This separation is generally less direct in Java/C++ when separating mutation from interface.&lt;/p&gt;&#xA;&#xA;&lt;h4 id=&#34;sequencing-effects-with-monads&#34;&gt;Sequencing effects with monads&lt;/h4&gt;&#xA;&lt;p&gt;The next topic is sequencing actions that may involve side effects, such as reading characters from input.&lt;/p&gt;&#xA;&lt;p&gt;Instead of hard-coding a specific effect type, this is written generically. The &lt;code&gt;Monad&lt;/code&gt; typeclass provides a way to sequence computations within a context &lt;code&gt;m&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The type is:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;seqn&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;::&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Monad&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;m&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;m&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For example: &lt;code&gt;seqn [getChar, getChar, getChar]&lt;/code&gt;, where &lt;code&gt;getChar&lt;/code&gt; is a standard function that reads a character from standard input in Haskell.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;do&lt;/code&gt; notation provides syntactic sugar for sequencing monadic operations, combined here with pattern matching and a base case:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;seqn&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;::&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Monad&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;m&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;m&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;seqn&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;[]&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;[]&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (1)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;seqn&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;act&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;do&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (2)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;act&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;xs&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;seqn&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;acts&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;xs&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;-- (3)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are a couple of new elements here:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;code&gt;&amp;lt;-&lt;/code&gt; is called &lt;strong&gt;monadic bind&lt;/strong&gt; operation. It runs the monadic action &lt;code&gt;act&lt;/code&gt;, extracts its result, and binds it to &lt;code&gt;x&lt;/code&gt; while staying in the context of the monad, for example the console input context.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;do&lt;/code&gt; provides a common way to write a sequence of monadic operations. First &lt;code&gt;act&lt;/code&gt; is run, for example &lt;code&gt;getChar&lt;/code&gt;, and its result is bound to &lt;code&gt;x&lt;/code&gt;. Then the same function is called on the remaining actions. Finally, &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;xs&lt;/code&gt; are combined, and &lt;code&gt;return&lt;/code&gt; is used to produce &lt;code&gt;m [a]&lt;/code&gt;; without &lt;code&gt;return&lt;/code&gt;, the result would be &lt;code&gt;[a]&lt;/code&gt;, which would not match the type signature.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2 id=&#34;summary&#34;&gt;Summary&lt;/h2&gt;&#xA;&lt;p&gt;This is the first part of a longer series.&lt;/p&gt;&#xA;&lt;p&gt;This section covered setting up a Haskell project in VS Code.&lt;/p&gt;&#xA;&lt;p&gt;It implemented several examples with types and functions, and demonstrated how expressive Haskell is with pattern matching and declarative syntax.&lt;/p&gt;&#xA;&lt;p&gt;It also provided an initial example of monads and &lt;code&gt;do&lt;/code&gt; notation.&lt;/p&gt;&#xA;&lt;p&gt;Overall, this illustrates how Haskell’s type-driven style supports reasoning about program structure and behavior even in early, small examples.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Programming in Haskell&lt;/em&gt; – Graham Hutton&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>UK income tax: the effects of the personal allowance taper</title>
      <link>https://lukastymo.com/posts/024-uk-income-tax/</link>
      <pubDate>Sun, 28 Dec 2025 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/024-uk-income-tax/</guid>
      <description>&lt;p&gt;&lt;em&gt;This analysis applies to England, Wales and Northern Ireland. Scotland, which operates a separate income tax system, is not covered.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Income tax is one of the UK government’s largest sources of revenue, paid by roughly 32 million taxpayers. While the system is progressive by design, it contains features that materially alter tax rates over relatively narrow income ranges.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;&lt;em&gt;This analysis applies to England, Wales and Northern Ireland. Scotland, which operates a separate income tax system, is not covered.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Income tax is one of the UK government’s largest sources of revenue, paid by roughly 32 million taxpayers. While the system is progressive by design, it contains features that materially alter tax rates over relatively narrow income ranges.&lt;/p&gt;&#xA;&lt;p&gt;One such feature — the withdrawal of the personal allowance above £100,000 — has led to widespread claims that income above this level is “taxed at 60 per cent”. That statement is accurate in a narrow sense, but misleading when applied to overall take-home pay.&lt;/p&gt;&#xA;&lt;p&gt;To understand why, it is necessary to distinguish between &lt;strong&gt;effective&lt;/strong&gt; and &lt;strong&gt;marginal&lt;/strong&gt; tax rates.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;effective-tax-rates&#34;&gt;Effective tax rates&lt;/h2&gt;&#xA;&lt;p&gt;The effective tax rate is defined as total income tax paid divided by total gross income. It compresses a complex, multi-band system into a single summary measure.&lt;/p&gt;&#xA;&lt;section class=&#34;scrolly&#34;&gt;&#xA;  &lt;div class=&#34;scrolly-figure&#34;&gt;&#xA;    &lt;img&#xA;      class=&#34;scrolly-img&#34;&#xA;      src=&#34;https://lukastymo.com/images/posts/024/01_take_home_01.svg&#34; data-start-mobile=&#34;/images/posts/024/01_take_home_01_mobile.svg&#34;alt=&#34;Chart&#34;&#xA;    /&gt;&#xA;  &lt;/div&gt;&#xA;  &lt;div class=&#34;scrolly-steps&#34;&gt;&#xA;    &#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/01_take_home_02.svg&#34; data-img-mobile=&#34;/images/posts/024/01_take_home_02_mobile.svg&#34;&gt;&#xA;  At lower income levels, the difference between gross and net income is modest.&#xA;At £100,000 — the highest income at which the full personal allowance applies — the effective income tax rate is approximately &lt;strong&gt;31 per cent&lt;/strong&gt;, equivalent to £31,444 in tax.&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/01_take_home_03.svg&#34; data-img-mobile=&#34;/images/posts/024/01_take_home_03_mobile.svg&#34;&gt;&#xA;  &lt;p&gt;Between £100,000 and £125,140, the personal allowance is gradually withdrawn at a rate of £1 for every £2 earned.&lt;/p&gt;&#xA;&lt;p&gt;This mechanism raises the effective marginal tax rate in this range to &lt;strong&gt;60 per cent&lt;/strong&gt;, despite the headline higher-rate band remaining at 40 per cent.&lt;/p&gt;&#xA;&lt;p&gt;By £150,000, total income tax paid reaches £58,714, corresponding to an effective rate of &lt;strong&gt;38 per cent&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/01_take_home_04.svg&#34; data-img-mobile=&#34;/images/posts/024/01_take_home_04_mobile.svg&#34;&gt;&#xA;  Above £125,140 — once the personal allowance has been fully withdrawn — the growth in the effective tax rate slows.&lt;br&gt;&#xA;At £250,000, the effective rate rises to approximately &lt;strong&gt;42 per cent&lt;/strong&gt;, an increase of only three percentage points over the previous £100,000 of income.&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;  &lt;/div&gt;&#xA;&lt;/section&gt;&#xA;&#xA;&#xA;&lt;p&gt;The personal allowance taper therefore produces a sharp increase in effective taxation over a relatively narrow income band, before stabilising again at higher income levels.&lt;/p&gt;&#xA;&lt;p&gt;The taper was introduced in 2010 and has not been adjusted for inflation, meaning it now affects a growing share of higher-earning taxpayers.&lt;/p&gt;&#xA;&lt;p&gt;At very high incomes, effective tax rates continue to rise, but at a diminishing pace.&lt;/p&gt;&#xA;&lt;div class=&#34;not-prose my-6&#34;&gt;&lt;picture&gt;&#xA;      &lt;source media=&#34;(max-width: 768px)&#34; srcset=&#34;https://lukastymo.com/images/posts/024/02_convergence_mobile.svg&#34;&gt;&#xA;      &lt;img class=&#34;w-full h-auto&#34; src=&#34;https://lukastymo.com/images/posts/024/02_convergence.svg&#34; alt=&#34;Average income tax rate converges&#34; /&gt;&#xA;    &lt;/picture&gt;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&lt;p&gt;By around £1 million of gross income, the effective income tax rate converges towards &lt;strong&gt;45–46 per cent&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;marginal-tax-rates&#34;&gt;Marginal tax rates&lt;/h2&gt;&#xA;&lt;p&gt;While effective tax rates describe overall tax burdens, &lt;strong&gt;marginal tax rates&lt;/strong&gt; determine incentives. They measure how much tax is paid on the next pound earned.&lt;/p&gt;&#xA;&lt;section class=&#34;scrolly&#34;&gt;&#xA;  &lt;div class=&#34;scrolly-figure&#34;&gt;&#xA;    &lt;img&#xA;      class=&#34;scrolly-img&#34;&#xA;      src=&#34;https://lukastymo.com/images/posts/024/02_marginal_tax_rate_01.svg&#34; data-start-mobile=&#34;/images/posts/024/02_marginal_tax_rate_01_mobile.svg&#34;alt=&#34;Chart&#34;&#xA;    /&gt;&#xA;  &lt;/div&gt;&#xA;  &lt;div class=&#34;scrolly-steps&#34;&gt;&#xA;    &#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/02_marginal_tax_rate_02.svg&#34; data-img-mobile=&#34;/images/posts/024/02_marginal_tax_rate_02_mobile.svg&#34;&gt;&#xA;  Marginal rates rise in steps as income crosses statutory thresholds.&lt;br&gt;&#xA;The most pronounced increase occurs between £100,000 and £125,140, where the withdrawal of the personal allowance raises the marginal rate to &lt;strong&gt;60 per cent&lt;/strong&gt;.&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/02_marginal_tax_rate_03.svg&#34; data-img-mobile=&#34;/images/posts/024/02_marginal_tax_rate_03_mobile.svg&#34;&gt;&#xA;  This produces a sequence of sharp jumps — from the basic rate, to the higher rate, and then to the allowance taper — rather than a smooth progression.&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;step step-left&#34; data-img=&#34;/images/posts/024/02_marginal_tax_rate_04.svg&#34; data-img-mobile=&#34;/images/posts/024/02_marginal_tax_rate_04_mobile.svg&#34;&gt;&#xA;  Once the personal allowance has been fully withdrawn, the marginal rate stabilises at &lt;strong&gt;45 per cent&lt;/strong&gt; for incomes above £125,140.&#xA;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;  &lt;/div&gt;&#xA;&lt;/section&gt;&#xA;&#xA;&#xA;&lt;p&gt;The distinction between marginal and effective rates explains why income above £100,000 can face very high taxation at the margin, while overall take-home pay continues to rise steadily.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-many-taxpayers-are-affected&#34;&gt;How many taxpayers are affected?&lt;/h2&gt;&#xA;&lt;p&gt;To place these thresholds in context, it is useful to examine their position within the income distribution.&lt;/p&gt;&#xA;&lt;div class=&#34;not-prose full-width-figure&#34;&gt;&lt;picture&gt;&#xA;      &lt;source media=&#34;(max-width: 768px)&#34; srcset=&#34;https://lukastymo.com/images/posts/024/03_population_by_income_band_mobile.svg&#34;&gt;&#xA;      &lt;img src=&#34;https://lukastymo.com/images/posts/024/03_population_by_income_band.svg&#34; alt=&#34;Four in five taxpayers earn below £50,000&#34; /&gt;&#xA;    &lt;/picture&gt;&lt;/div&gt;&#xA;&#xA;&#xA;&#xA;&lt;div class=&#34;not-prose mt-3 mb-3 text-sm text-gray-500 dark:text-gray-400 font-sans leading-snug&#34;&gt;&#xA;    &lt;span class=&#34;uppercase tracking-wider&#34;&gt;Source&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;a class=&#34;underline decoration-gray-300 dark:decoration-gray-700 underline-offset-4 hover:decoration-gray-500 dark:hover:decoration-gray-400&#34; href=&#34;https://www.gov.uk/government/statistics/percentile-points-from-1-to-99-for-total-income-before-and-after-tax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Percentile points from 1 to 99 for total income before and after tax: 1992 to 1993 to 2022 to 2023&lt;/a&gt;&lt;/div&gt;&#xA;&lt;p&gt;Around &lt;strong&gt;80 per cent&lt;/strong&gt; of UK taxpayers earn less than £50,000.&lt;br&gt;&#xA;Only a small fraction earn enough to enter the personal allowance taper, and fewer still reach the additional-rate threshold.&lt;/p&gt;&#xA;&lt;p&gt;Because income is unevenly distributed within percentiles, tax thresholds may fall inside percentile bands, introducing minor rounding effects at the top of the distribution.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;sources-and-methodology&#34;&gt;Sources and methodology&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;HMRC percentile income statistics&lt;br&gt;&#xA;&lt;a href=&#34;https://www.gov.uk/government/statistics/percentile-points-from-1-to-99-for-total-income-before-and-after-tax&#34;&gt;https://www.gov.uk/government/statistics/percentile-points-from-1-to-99-for-total-income-before-and-after-tax&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;UK income tax rates and thresholds&lt;br&gt;&#xA;&lt;a href=&#34;https://www.gov.uk/income-tax-rates&#34;&gt;https://www.gov.uk/income-tax-rates&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;National Insurance contribution rates&lt;br&gt;&#xA;&lt;a href=&#34;https://www.gov.uk/national-insurance-rates-letters&#34;&gt;https://www.gov.uk/national-insurance-rates-letters&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>My Side Projects and Self-Development Plan for 2025</title>
      <link>https://lukastymo.com/posts/023-my-side-projects-in-2025/</link>
      <pubDate>Mon, 16 Jun 2025 17:11:55 +0100</pubDate>
      <guid>https://lukastymo.com/posts/023-my-side-projects-in-2025/</guid>
      <description>&lt;h2 id=&#34;1-3monads&#34;&gt;1. &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:023-my-side-projects-in-2025&#34;&gt;3Monads&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/023/3monads.png&#34; alt=&#34;3Monads&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is my personal project to replace the task manager I currently use. My goal is to build a tool with better calendar integration,&#xA;improved note-taking support, and Vim-like navigation. I also want to support tasks belonging&#xA;to multiple projects and eliminate the trend of unnecessary AI integrations — focusing instead on a clean,&#xA;minimalistic, Vim-inspired interface that puts the user in control.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;h2 id=&#34;1-3monads&#34;&gt;1. &lt;a href=&#34;https://3monads.com/?utm_source=lukastymo.com&amp;amp;utm_medium=blog&amp;amp;utm_campaign=3monads&amp;amp;utm_content=inline_link:023-my-side-projects-in-2025&#34;&gt;3Monads&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/023/3monads.png&#34; alt=&#34;3Monads&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is my personal project to replace the task manager I currently use. My goal is to build a tool with better calendar integration,&#xA;improved note-taking support, and Vim-like navigation. I also want to support tasks belonging&#xA;to multiple projects and eliminate the trend of unnecessary AI integrations — focusing instead on a clean,&#xA;minimalistic, Vim-inspired interface that puts the user in control.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Release the simplest possible version: CRUD for tasks, projects, tags, and notes.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;2-my-personal-websiteblog--&#34;&gt;2. My personal website/blog - &lt;a href=&#34;https://lukastymo.com/&#34;&gt;https://lukastymo.com/&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;I keep a lot of notes in my second brain (Roam Research). I want to externalize them so others can benefit — and there’s no better way to learn than by teaching.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Publish 10 blog posts in 2025.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;3-etl-magic-formula&#34;&gt;3. ETL Magic Formula&lt;/h2&gt;&#xA;&lt;p&gt;I use the Magic Formula as my quantitative investing strategy. I’ve built a Python pipeline that screens stocks from the Russell 1000 universe. I believe it has the potential to become a subscription-based service.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Launch a demo website showcasing the strategy and allowing users to subscribe.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;4-leetcode-and-codeforces&#34;&gt;4. Leetcode and Codeforces&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Solve and submit one Leetcode and one Codeforces problem each day.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Codeforces progress so far:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/023/codeforces.png&#34; alt=&#34;Codeforces progress so far&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Leetcode progress so far:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/023/leetcode.png&#34; alt=&#34;Leetcode progress so far&#34;&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;5-learning&#34;&gt;5. Learning&lt;/h2&gt;&#xA;&lt;p&gt;Main focus:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Neural Networks, LLMs&lt;/li&gt;&#xA;&lt;li&gt;React &amp;amp; TailwindCSS&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Bonus (if time allows):&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Haskell&lt;/li&gt;&#xA;&lt;li&gt;TypeScript&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;6-books&#34;&gt;6. Books&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;How Countries Go Broke&lt;/em&gt; — Ray Dalio&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Neural Networks from Scratch&lt;/em&gt; — Harrison Kinsley&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;The Concepts and Practice of Mathematical Finance&lt;/em&gt; — Mark S. Joshi&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;System Design Interview&lt;/em&gt; — Alex Xu&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Designing Data-Intensive Applications&lt;/em&gt; — Martin Kleppmann&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Why Machines Learn: The Elegant Math Behind Modern AI&lt;/em&gt; — Anil Ananthaswamy&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;7-course&#34;&gt;7. Course&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=VMj-3S1tku0&amp;amp;list=PLAqhIrjkxbuWI23v9cThsA9GvCAUhRvKZ&#34;&gt;Andrej Karpathy — Neural Networks: Zero to Hero&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;8-sport&#34;&gt;8. Sport&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Run a half marathon (20 km)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>[Scala] Fundamental Concurrency Problems and Solutions</title>
      <link>https://lukastymo.com/posts/022-concurrency-basic-synchronization/</link>
      <pubDate>Mon, 16 Jun 2025 13:36:55 +0100</pubDate>
      <guid>https://lukastymo.com/posts/022-concurrency-basic-synchronization/</guid>
      <description>&lt;p&gt;The best way to approach concurrency is to master the fundamentals.&#xA;Below is a small collection of foundational concurrency problems with practical solutions using Scala and Cats Effect.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;In this post, we explore four fundamental concurrency problems and their idiomatic solutions using Scala and Cats Effect,&#xA;but which could be generalized to any programming language with concurrency support.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;The best way to approach concurrency is to master the fundamentals.&#xA;Below is a small collection of foundational concurrency problems with practical solutions using Scala and Cats Effect.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;In this post, we explore four fundamental concurrency problems and their idiomatic solutions using Scala and Cats Effect,&#xA;but which could be generalized to any programming language with concurrency support.&lt;/p&gt;&#xA;&lt;p&gt;After reading this post, you should be able to:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Mutex for synchronizing access to shared resources&lt;/li&gt;&#xA;&lt;li&gt;Semaphore for limiting the number of concurrent tasks&lt;/li&gt;&#xA;&lt;li&gt;CyclicBarrier for synchronizing tasks at a common point&lt;/li&gt;&#xA;&lt;li&gt;CountDownLatch for waiting for a signal before proceeding with tasks&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;problem-1-counter-updated-in-parallel-mutex&#34;&gt;Problem 1: Counter Updated in Parallel (Mutex)&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-problem&#34;&gt;❌ The Problem&lt;/h3&gt;&#xA;&lt;p&gt;Suppose we have a simple counter that is incremented by 1000 tasks running in parallel.&#xA;Without synchronization, we get incorrect results.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.unsafe.implicits.global&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scala.util.Random&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mutexDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// Problem&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.syntax.parallel.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// shared, unsafe&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;increment&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tmp&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nc&#34;&gt;Thread&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// it makes the problem more visible, as we wait &#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tmp&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;List&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fill&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;increment&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parSequence&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;101&lt;/span&gt; //  different results every &lt;span class=&#34;nb&#34;&gt;time&lt;/span&gt; you run it.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is due to &lt;code&gt;counter += 1&lt;/code&gt; being a non-atomic read-modify-write operation.&#xA;In assembly, it roughly translates to:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-asm&#34; data-lang=&#34;asm&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;mov&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;eax&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;counter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;; read counter&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;add&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;eax&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;          &lt;span class=&#34;c1&#34;&gt;; increment&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;mov&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;counter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;eax&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;; write back&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When multiple tasks interleave at these instructions, updates are lost.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-solution-mutex&#34;&gt;✅ The Solution: Mutex&lt;/h3&gt;&#xA;&lt;p&gt;To fix the problem, we use a mutex — a mutual exclusion lock that ensures only one task modifies the counter at a time.&#xA;In Cats Effect, we can implement a mutex using a Semaphore with a single permit:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mutexDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// reset&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// Solution&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.std.Semaphore&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;mutex&lt;/span&gt;    &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Semaphore&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;](&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;n&#34;&gt;increment&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mutex&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;permit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;use&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;        &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;List&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fill&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;increment&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parSequence&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;        &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;counter&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;1000&lt;/span&gt; //  every &lt;span class=&#34;nb&#34;&gt;time&lt;/span&gt; you run it&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h2 id=&#34;problem-2-max-10-workers-in-parallel-semaphore&#34;&gt;Problem 2: Max 10 Workers in Parallel (Semaphore)&lt;/h2&gt;&#xA;&lt;p&gt;In this example, we want to run 50 tasks but allow only 10 to run in parallel.&lt;/p&gt;&#xA;&lt;p&gt;Using a mutex (as in the previous example) would require us to manually track the number of active tasks and implement a queue or backpressure mechanism, which adds unnecessary complexity.&lt;/p&gt;&#xA;&lt;p&gt;Instead, we’ll use a simpler and more idiomatic solution.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-problem-1&#34;&gt;❌ The Problem&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.std.Semaphore&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.syntax.parallel.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scala.util.Random&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scala.concurrent.duration.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.unsafe.implicits.global&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;semaphoreDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// Problem: Run 50 tasks, but only 10 in parallel&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runTask&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;currRef&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;, &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeen&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;, &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;])&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;running&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;currRef&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;updateAndGet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeen&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;update&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;math&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;max&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;m&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;running&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;[&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;] running (current: &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$running&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;300&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;millisecond&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;currRef&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;update&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;end&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runTask&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;running&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;].&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;of&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;maxSeen&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;].&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;of&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;50&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runTask&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;running&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeen&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;max&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeen&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;get&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Max concurrently running tasks: &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$max&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Max concurrently running tasks: &lt;span class=&#34;m&#34;&gt;50&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Clearly not what we want — we expected a cap at 10.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-solution-semaphore&#34;&gt;✅ The Solution: Semaphore&lt;/h3&gt;&#xA;&lt;p&gt;A semaphore is a synchronization primitive that limits the number of concurrent accesses to a resource.&lt;/p&gt;&#xA;&lt;p&gt;Here, we use a semaphore with 10 permits to allow at most 10 tasks to run in parallel.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;semaphoreDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;runningRef&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;].&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;of&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;maxSeenRef&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Ref&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;].&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;of&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;semaphore&lt;/span&gt;  &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Semaphore&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;](&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;guarded&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;semaphore&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;permit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;use&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runTask&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;runningRef&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeenRef&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;          &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;50&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;guarded&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;max&lt;/span&gt;        &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;maxSeenRef&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;get&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;          &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Max concurrently running tasks: &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$max&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Each task acquires a permit before running, ensuring that no more than 10 run concurrently.&#xA;Once a task completes, it releases its permit, allowing another task to proceed.&lt;/p&gt;&#xA;&lt;p&gt;Outupt: &lt;code&gt;Max concurrently running tasks: 10&lt;/code&gt; // each time you run it.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;problem-3-wait-for-all-tasks-to-be-ready-barrier&#34;&gt;Problem 3: Wait for All Tasks to Be Ready (Barrier)&lt;/h2&gt;&#xA;&lt;p&gt;In this example, we want to run 5 tasks, but ensure they all wait until everyone is ready before proceeding to the next step.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-problem-2&#34;&gt;❌ The Problem&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.IO&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.std.CyclicBarrier&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scala.util.Random&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scala.concurrent.duration.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.syntax.parallel.&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;cats.effect.unsafe.implicits.global&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;barrierDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt; preparing&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;500&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;millis&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;: Preparing done&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;: Doing what I want to do&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// no waiting&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;500&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;millis&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;task&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;5&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 2: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 2: Doing what I want to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 3: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 3: Doing what I want to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 1: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 1: Doing what I want to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 4: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 4: Doing what I want to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 5: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 5: Doing what I want to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Each task simulates a &amp;ldquo;preparing&amp;rdquo; phase, followed by the actual work. However, without coordination, tasks begin their work as soon as they finish preparing. There’s no synchronization point — they continue independently.&lt;/p&gt;&#xA;&lt;p&gt;This means some tasks might proceed while others are still preparing, which isn&amp;rsquo;t the desired behavior when you want them to start simultaneously.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-solution-barrier&#34;&gt;✅ The Solution: Barrier&lt;/h3&gt;&#xA;&lt;p&gt;To fix this, we use a &lt;code&gt;CyclicBarrier&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A &lt;strong&gt;cyclic barrier&lt;/strong&gt; is a synchronization primitive that blocks all participating tasks at a certain point (the barrier) until all have reached it. Only once all tasks are ready does the barrier open, allowing them to proceed together.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;barrierDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;barrier&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;CyclicBarrier&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt; preparing&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;500&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;millis&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;: Preparing done&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;barrier&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;await&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;Task &lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;: Doing what I want to do&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// no waiting&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;Random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;between&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;500&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;millis&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;barrier&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;CyclicBarrier&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;](&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;       &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;barrier&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;5&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt; preparing&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 3: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 1: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 4: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 5: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 2: Preparing &lt;span class=&#34;k&#34;&gt;done&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 2: Doing what I what to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 4: Doing what I what to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 5: Doing what I what to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 3: Doing what I what to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Task 1: Doing what I what to &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Much more obidient tasks!&lt;/p&gt;&#xA;&lt;p&gt;In our case, after each task finishes preparing, it waits at the barrier. Once all 5 tasks reach it, they continue in parallel.&lt;/p&gt;&#xA;&lt;p&gt;This guarantees that no task starts the &amp;ldquo;real&amp;rdquo; work until everyone is ready — perfect for scenarios where coordination matters, such as simulations, games, or collective task triggers.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;problem-4-wait-until-signal-to-start-latch&#34;&gt;Problem 4: Wait Until Signal to Start (Latch)&lt;/h2&gt;&#xA;&lt;p&gt;The final problem in this post is about delaying the start of tasks until a signal is given.&lt;/p&gt;&#xA;&lt;p&gt;Imagine you have a set of tasks that shouldn&amp;rsquo;t start immediately — they should wait for a &amp;ldquo;go&amp;rdquo; signal.&lt;br&gt;&#xA;This is a common pattern in concurrent systems where you want to ensure everything is prepared before kicking off execution.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-problem-3&#34;&gt;❌ The Problem&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latchesDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;[&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;] running too early&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;1.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;second&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse_&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;task&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the naive version, tasks are simply launched after a short delay. There&amp;rsquo;s no coordination — they run as soon as they&amp;rsquo;re scheduled. This doesn&amp;rsquo;t satisfy the requirement of waiting for an external signal.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;-the-solution-latch&#34;&gt;✅ The Solution: Latch&lt;/h3&gt;&#xA;&lt;p&gt;To fix this, we use a &lt;code&gt;CountDownLatch&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A &lt;strong&gt;latch&lt;/strong&gt; is a synchronization primitive that allows one or more tasks to wait until a signal is given (e.g., a counter hits zero).&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latchesDemo&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;// ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Int&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latch&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;CountDownLatch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;[&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;] Waiting for signal&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;await&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;s&amp;#34;[&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;$id&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;] Processing after signal (latch released)&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;latch&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;CountDownLatch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;](&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;fiber&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toList&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;parTraverse_&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;task2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)).&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;start&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// ! we start a fiber&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;All tasks should wait for signal!&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sleep&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;5.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;seconds&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IO&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;Setup complete&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;latch&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;release&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;k&#34;&gt;_&lt;/span&gt;     &lt;span class=&#34;k&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;fiber&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;yield&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;program2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unsafeRunSync&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;2&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Waiting &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;3&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Waiting &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;1&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Waiting &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;4&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Waiting &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;All tasks should &lt;span class=&#34;nb&#34;&gt;wait&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal!&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;5&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Waiting &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; signal&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Setup &lt;span class=&#34;nb&#34;&gt;complete&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;1&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Processing after signal &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;latch released&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;2&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Processing after signal &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;latch released&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;4&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Processing after signal &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;latch released&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;3&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Processing after signal &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;latch released&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;5&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt; Processing after signal &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;latch released&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In our case, we use a latch with an initial count of 1. All tasks call &lt;code&gt;await&lt;/code&gt;, blocking until the latch is released. Once we call &lt;code&gt;release&lt;/code&gt;, all tasks proceed.&lt;/p&gt;&#xA;&lt;p&gt;We also start the tasks inside a fiber so they can run in parallel and reach the waiting point without blocking the rest of the program.&lt;/p&gt;&#xA;&lt;p&gt;The key moment is when we release the latch — only then do the tasks resume and continue&lt;/p&gt;&#xA;&lt;p&gt;This pattern is useful when you want a coordinated start after setup or resource allocation is complete.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;-recommended-books&#34;&gt;📚 Recommended Books&lt;/h2&gt;&#xA;&lt;p&gt;There are plenty of great books on concurrency, both general and specific to Scala/Java. Here are some recommendations:&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;general-concepts&#34;&gt;General concepts&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;The Little Book of Semaphores&lt;/em&gt; – Allen B. Downey&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Operating Systems: Three Easy Pieces&lt;/em&gt; (Part II: Concurrency)&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;The Art of Multiprocessor Programming&lt;/em&gt; – Maurice Herlihy &amp;amp; Nir Shavit&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Modern Operating Systems&lt;/em&gt; – Andrew Tanenbaum&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3 id=&#34;javascala-specific&#34;&gt;Java/Scala Specific&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Java Concurrency in Practice&lt;/em&gt; – Brian Goetz&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Programming Concurrency on the JVM&lt;/em&gt; – Venkat Subramaniam&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Functional Programming in Scala&lt;/em&gt; – Paul Chiusano &amp;amp; Rúnar Bjarnason (Chapter 12: Concurrency)&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Advanced Scala with Cats&lt;/em&gt; – Noel Welsh &amp;amp; Dave Gurnell (Chapter 8: Concurrency)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3 id=&#34;distributed-systems&#34;&gt;Distributed Systems&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Designing Data-Intensive Applications&lt;/em&gt; – Martin Kleppmann (Chapter 6: Distributed Systems)&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Reactive Design Patterns&lt;/em&gt; – Roland Kuhn, Jamie Allen &amp;amp; Brian Hanafee (Chapter 2: Concurrency)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>[Scala] Quick experimentation vs -Xfatal-warnings flag in sbt</title>
      <link>https://lukastymo.com/posts/021-sbt-settings-for-exp/</link>
      <pubDate>Fri, 13 Jun 2025 09:16:12 +0100</pubDate>
      <guid>https://lukastymo.com/posts/021-sbt-settings-for-exp/</guid>
      <description>&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;&#xA;&lt;p&gt;I’ve always had mixed feelings about &lt;code&gt;scalacOptions += &amp;quot;-Xfatal-warnings&amp;quot;&lt;/code&gt;. On one hand, it’s an inevitable PR review and code quality boost—I no longer have to comment on unused variables or imports. On the other hand, it kills experimentation and creativity. I’ve spent countless hours fixing unused variables and imports just to test something quickly.&lt;/p&gt;</description>
      <content:encoded>&#xA;&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;&#xA;&lt;p&gt;I’ve always had mixed feelings about &lt;code&gt;scalacOptions += &amp;quot;-Xfatal-warnings&amp;quot;&lt;/code&gt;. On one hand, it’s an inevitable PR review and code quality boost—I no longer have to comment on unused variables or imports. On the other hand, it kills experimentation and creativity. I’ve spent countless hours fixing unused variables and imports just to test something quickly.&lt;/p&gt;&#xA;&lt;p&gt;This issue only arises when &lt;code&gt;-Xfatal-warnings&lt;/code&gt; is enabled in &lt;code&gt;build.sbt&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;problematic-code-unused-variables-cause-compilation-error&#34;&gt;Problematic code: Unused variables cause compilation error&lt;/h2&gt;&#xA;&lt;p&gt;[build.sbt]&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nc&#34;&gt;ThisBuild&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scalaVersion&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;3.3.1&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;lazy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;root&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;project&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;in&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;file&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;.&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;settings&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;minimal-project&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;scalacOptions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;++=&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Seq&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;s&#34;&gt;&amp;#34;-deprecation&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt;      &lt;span class=&#34;c1&#34;&gt;// show deprecation warnings&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;s&#34;&gt;&amp;#34;-unchecked&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;,&lt;/span&gt;        &lt;span class=&#34;c1&#34;&gt;// additional warnings&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;s&#34;&gt;&amp;#34;-Xfatal-warnings&amp;#34;&lt;/span&gt;   &lt;span class=&#34;c1&#34;&gt;// treat warnings as errors&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;[article21.scala]&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;package&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;blog.article21&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@main&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;demoProblem&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;Unit&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// boom&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;unused&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;String&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;hello&amp;#34;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;// boom&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This results in compilation errors like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/021/code.png&#34; alt=&#34;Demo of the problem in code&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;We can’t even run our little experiment without resolving all warnings first. Frustrating!&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/021/error.png&#34; alt=&#34;Error in IDE&#34;&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;solution&#34;&gt;Solution&lt;/h2&gt;&#xA;&lt;p&gt;We can modify the global: &lt;code&gt;~/.sbt/1.0/global.sbt&lt;/code&gt; file to disable &lt;code&gt;-Xfatal-warnings&lt;/code&gt; when running inside the IDE, while keeping it enabled in the command line.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;before-we-dive-into-the-solution&#34;&gt;Before We Dive into the Solution&lt;/h2&gt;&#xA;&lt;p&gt;Here are some approaches I tried before finding the one I now use.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;approach-1-bad-idea&#34;&gt;Approach 1 (bad idea)&lt;/h3&gt;&#xA;&lt;p&gt;Just drop &lt;code&gt;-Xfatal-warnings&lt;/code&gt; completely. Sure, it&amp;rsquo;s faster for prototyping—good for startups maybe? But it&amp;rsquo;s an oversimplification and a missed opportunity. Scala’s strong typing and compiler warnings can help you catch issues early and reduce PR nitpicks and conflicts.&lt;/p&gt;&#xA;&lt;p&gt;Also, I’ve seen projects without this flag—it&amp;rsquo;s always the same story: tons of warnings and no way to know if your change added new ones.&lt;/p&gt;&#xA;&lt;p&gt;Did I imagine it, or did some teams in the &amp;rsquo;90s track warnings per project in an external backlog? 😅&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;approach-2-meh&#34;&gt;Approach 2 (meh)&lt;/h3&gt;&#xA;&lt;p&gt;Add conditional logic to each build.sbt, using an environment variable to toggle the flag.&lt;/p&gt;&#xA;&lt;p&gt;It worked, but I had to modify every project and invent a variable like SCALA_DISABLE_FATAL. Not a huge deal—unless you’re a guest contributor who doesn’t want to touch the build on your first PR.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;approach-3-worse&#34;&gt;Approach 3 (worse)&lt;/h3&gt;&#xA;&lt;p&gt;Live with it. “It’s not a big deal to remove an unused import.” Actually—it is. When you&amp;rsquo;re in a creative flow, you don’t want to be interrupted by compiler nags or have to constantly delete and re-add code just to run println.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;a-better-solution&#34;&gt;A Better Solution&lt;/h2&gt;&#xA;&lt;p&gt;Wouldn’t it be great if:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;In the IDE, you’re free to experiment.&lt;/li&gt;&#xA;&lt;li&gt;In the terminal (or CI), fatal warnings are strictly enforced.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;SBT automatically includes a file located at &lt;code&gt;~/.sbt/1.0/global.sbt&lt;/code&gt;. We can use it to conditionally tweak compiler flags.&lt;/p&gt;&#xA;&lt;p&gt;[~/.sbt/1.0/global.sbt]&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-scala&#34; data-lang=&#34;scala&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sys&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;props&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;contains&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;idea.managed&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;match&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;case&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;println&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;scalacOptions&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Compile&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--=&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Seq&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;-Xfatal-warnings&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;case&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scalacOptions&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--=&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Seq&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This disables &lt;code&gt;-Xfatal-warnings&lt;/code&gt; only inside IntelliJ, so you can freely experiment. Reload the SBT project, and you&amp;rsquo;re all set.&lt;/p&gt;&#xA;&lt;p&gt;Meanwhile, building from the command line (like in CI) still enforces the flag—preserving the quality gate.&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>10 Years of Codeily LTD: A Decade of Growth and Learning</title>
      <link>https://lukastymo.com/posts/020-10-years-codeily-ltd/</link>
      <pubDate>Sat, 15 Jun 2024 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/020-10-years-codeily-ltd/</guid>
      <description>&lt;p&gt;Ten years ago, I made a pivotal decision that changed my career trajectory—I incorporated my own company, Codeily LTD. This move allowed me to transition from a permanent role, where I often felt unfulfilled and bored after about a year, to becoming a contractor. Despite the bad press and disdain from my permanent colleagues, it was one of the best decisions I’ve ever made. Alongside choosing Scala as my main programming language, this choice has brought immense satisfaction and growth.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;Ten years ago, I made a pivotal decision that changed my career trajectory—I incorporated my own company, Codeily LTD. This move allowed me to transition from a permanent role, where I often felt unfulfilled and bored after about a year, to becoming a contractor. Despite the bad press and disdain from my permanent colleagues, it was one of the best decisions I’ve ever made. Alongside choosing Scala as my main programming language, this choice has brought immense satisfaction and growth.&lt;/p&gt;&#xA;&lt;p&gt;I benefited greatly from the contract market before Brexit, IR35, and Covid, reaching an all-time high rate of £800 per day (outside IR35) and on a promising path towards a four-digit daily rate. More importantly, this journey enabled me to explore a myriad of technologies, encounter diverse management styles, and build a vast network of passionate technologists like myself.&lt;/p&gt;&#xA;&lt;p&gt;Many of the companies I’ve worked with suffer from similar problems, often centered around people rather than technology. Different agendas, styles, and understandings can complicate even the simplest projects. Through Codeily LTD, I’ve helped high-profile companies deliver their innovations, all while pursuing continuous learning. Switching jobs every 6-12 months keeps you interview-ready, forcing you to stay sharp and open-minded about various paradigms. This constant evolution led me to pursue an MBA and a third Master’s Degree in Applied Data Science. Mastering Functional Programming became a necessity as I realized, through numerous interviews, how much there was still to learn. This would have been impossible if I had climbed the career ladder in a single company.&lt;/p&gt;&#xA;&lt;p&gt;Running my own company taught me to be my own accountant and understand financial statements, which sparked my interest in investing—specifically value investing—and deepened my understanding of how businesses and financial markets operate.&lt;/p&gt;&#xA;&lt;p&gt;Interestingly, some companies claim to hire the best programmers but then reject candidates based on their CVs. I&amp;rsquo;ve experienced this rejection either because I&amp;rsquo;m a contractor seeking a permanent role—some companies believe once you&amp;rsquo;ve done contracting, that&amp;rsquo;s it—or because I lack recent fintech experience. Such narrow hiring criteria miss out on a wealth of opportunities and diverse skill sets. However, I see this as a positive filter. Companies with shallow hiring practices, often managed by people who don’t fully understand software development, likely wouldn’t provide an enjoyable working environment. Conversely, the companies that rejected me after interviews hold a special place in my heart as challenges I have yet to overcome.&lt;/p&gt;&#xA;&lt;p&gt;I recommend everyone to experience being the Director of their own company. It opens your eyes to the world around you and can be a great antidote to burnout, as short contracts always bring something fresh. As I look forward to the next decade of Codeily LTD, I’m ready to pivot from consulting (selling my time) towards developing a product-based company.&lt;/p&gt;&#xA;&lt;p&gt;Here’s to the next 10 years. See you in 2034!&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Using Pandas and NLTK for Simple Data Analysis: A Beginner&#39;s Guide</title>
      <link>https://lukastymo.com/posts/019-pandas-and-nltk-sentiment-for-data-analysis/</link>
      <pubDate>Sat, 26 Aug 2023 00:00:00 +0000</pubDate>
      <guid>https://lukastymo.com/posts/019-pandas-and-nltk-sentiment-for-data-analysis/</guid>
      <description>&lt;p&gt;Data analysis doesn&amp;rsquo;t always have to be intimidating. By leveraging powerful Python libraries and Google Colab&amp;rsquo;s user-friendly platform,&#xA;you can dive into data analysis without any installations or setups. This guide is tailored for beginners and will&#xA;walk you through a practical application: analyzing survey comments.&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;Data analysis doesn&amp;rsquo;t always have to be intimidating. By leveraging powerful Python libraries and Google Colab&amp;rsquo;s user-friendly platform,&#xA;you can dive into data analysis without any installations or setups. This guide is tailored for beginners and will&#xA;walk you through a practical application: analyzing survey comments.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;problem-statement&#34;&gt;Problem Statement&lt;/h2&gt;&#xA;&lt;p&gt;You&amp;rsquo;re handed a survey dataset. While columns filled with numbers might look more manageable,&#xA;the &lt;strong&gt;&amp;lsquo;comments&amp;rsquo;&lt;/strong&gt; column, brimming with text, looks daunting. Reading each comment? Time-consuming and inefficient.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;the-power-trio-python--pandas--nltk-on-google-colab&#34;&gt;The Power Trio: Python + Pandas + NLTK on Google Colab&lt;/h2&gt;&#xA;&lt;p&gt;Google Colab is a free-to-use platform that allows Python coding in the cloud. Couple this with the capabilities of Pandas and NLTK, and you&amp;rsquo;ve got a robust toolkit to tackle your data.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 1: Setting up on Google Colab&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open &lt;a href=&#34;https://colab.research.google.com/?utm_source=scs-index&#34;&gt;Google Colab&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Navigate to  &lt;code&gt;File &amp;gt; New Notebook&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Familiarize yourself with the interface. To rename your notebook, click on the default &amp;lsquo;Untitled0.ipynb&amp;rsquo;.&lt;/li&gt;&#xA;&lt;li&gt;To execute any code cell, press Shift + Enter.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/019/step1.png&#34; alt=&#34;Step 1&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;Test your setup: Type &lt;code&gt;2 + 2&lt;/code&gt; in a new cell and press &lt;code&gt;Shift + Enter&lt;/code&gt;. Voila, you should see the number 4!&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/019/step1A.png&#34; alt=&#34;2 + 2&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 2: Fetch the Dataset&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Download the &lt;a href=&#34;https://www.kaggle.com/datasets/osmi/mental-health-in-tech-survey&#34;&gt;sample survey data&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Unzip the file to reveal the CSV.&lt;/li&gt;&#xA;&lt;li&gt;Return to Google Colab and execute:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-gdscript3&#34; data-lang=&#34;gdscript3&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;google&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;colab&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;files&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;files&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;upload&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A prompt will appear. Upload your CSV. This process places the CSV in Colab&amp;rsquo;s virtual &lt;code&gt;/content&lt;/code&gt; directory.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 3: Harness the Libraries&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Load the essential libraries by running the code below. These modules are the workhorses behind our data manipulation and analysis:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;string&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;collections&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Counter&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pandas&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pd&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk.corpus&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stopwords&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk.corpus&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk.sentiment&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;SentimentIntensityAnalyzer&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk.stem&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;WordNetLemmatizer&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;nltk.tokenize&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word_tokenize&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h2 id=&#34;step-4-preparing-the-data&#34;&gt;Step 4: Preparing the Data&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;1-loading-the-dataset&#34;&gt;1. Loading the Dataset:&lt;/h3&gt;&#xA;&lt;p&gt;Load the dataset into a pandas DataFrame:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pd&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;read_csv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;/content/survey.csv&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Inspect the initial rows to understand the dataset structure:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/019/step4A.png&#34; alt=&#34;df.head(20)&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;The snapshot of the dataset will give you an overview of its structure and potential issues. (Please refer to the image for an actual visual.)&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;2-handling-missing-values&#34;&gt;2. Handling Missing Values:&lt;/h3&gt;&#xA;&lt;p&gt;If you observed &amp;lsquo;NaN&amp;rsquo; entries in the &amp;lsquo;comments&amp;rsquo; column, these typically represent missing data. Such values could be due to various reasons like incomplete user responses or issues during survey data collection.&lt;/p&gt;&#xA;&lt;p&gt;For our purpose, we&amp;rsquo;ll treat these missing comments by replacing them with an empty string:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;clean_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fillna&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h3 id=&#34;3-preparing-the-tools&#34;&gt;3. Preparing the Tools:&lt;/h3&gt;&#xA;&lt;p&gt;Before we delve into sentiment analysis, let&amp;rsquo;s set up the necessary tools. First, ensure that the NLTK library has all required datasets:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;punkt&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;wordnet&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;stopwords&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;averaged_perceptron_tagger&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;vader_lexicon&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, initialize the text processing tools:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;lemmatizer&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;WordNetLemmatizer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;stop_words&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;set&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;stopwords&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;words&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;english&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The WordNetLemmatizer is a tool from the Natural Language Toolkit (NLTK) for Python.&#xA;It is used to perform lemmatization on words. Let&amp;rsquo;s break down what lemmatization means and how the WordNetLemmatizer works:&lt;/p&gt;&#xA;&lt;p&gt;Lemmatization is a process in natural language processing (NLP) where we convert a word to its base or root form. For example:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&amp;quot;running&amp;quot; → &amp;quot;run&amp;quot;&#xA;&amp;quot;better&amp;quot; → &amp;quot;good&amp;quot;&#xA;&amp;quot;geese&amp;quot; → &amp;quot;goose&amp;quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The main idea is to reduce inflected (or sometimes derived) words to a base or dictionary form.&#xA;This is often useful in text processing tasks like text classification or clustering, as it can reduce the dimensionality of the dataset and allow different forms of a word to be treated as the same.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;4-text-preprocessing&#34;&gt;4. Text Preprocessing:&lt;/h3&gt;&#xA;&lt;p&gt;To ensure that our sentiment analysis is accurate, it&amp;rsquo;s essential to preprocess the comments. This includes tokenization, lemmatization, and removing stop words:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_wordnet_pos&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;treebank_tag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&amp;#34;Map POS tag to first character used by WordNetLemmatizer&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;treebank_tag&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;startswith&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;J&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ADJ&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;elif&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;treebank_tag&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;startswith&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;V&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;VERB&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;elif&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;treebank_tag&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;startswith&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;N&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NOUN&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;elif&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;treebank_tag&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;startswith&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;R&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ADV&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;wordnet&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NOUN&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# by default, treat as noun&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;preprocess_text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word_tokenize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lower&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isalpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;punctuation&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;pos_tags&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;nltk&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pos_tag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lemmatizer&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lemmatize&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;get_wordnet_pos&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pos&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pos&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pos_tags&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stop_words&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tokens&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;clean_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;apply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;preprocess_text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The DataFrame now has a new column, &lt;strong&gt;&amp;lsquo;processed_comments&amp;rsquo;&lt;/strong&gt;, which contains the processed text. (Please refer to the image for a visual overview.)&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/019/step4B.png&#34; alt=&#34;normalized comments&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;With our data prepared, we&amp;rsquo;re set to move to the next step: Sentiment Analysis.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;step-5-analyzing-sentiments&#34;&gt;Step 5: Analyzing Sentiments&lt;/h2&gt;&#xA;&lt;p&gt;To get insights from the comments, we&amp;rsquo;ll first categorize them based on sentiment using the SentimentIntensityAnalyzer:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sia&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;SentimentIntensityAnalyzer&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;get_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;sentiment_score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sia&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;polarity_scores&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;compound&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sentiment_score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.05&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;positive&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;elif&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sentiment_score&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.05&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;negative&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;neutral&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;sentiment_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;apply&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;get_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s now inspect our dataset with the newly added sentiment column:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;cols&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;clean_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;sentiment_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cols&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To further analyze, we&amp;rsquo;ll segregate the comments based on their sentiment:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df_sentiment&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cols&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;negatives_df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;sentiment_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;negative&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;][[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;negatives&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;negatives_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tolist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;positives_df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;df_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df_sentiment&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;sentiment_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;positive&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;][[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;positives&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;positives_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tolist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s preview some of the comments to better understand the sentiments:&lt;/p&gt;&#xA;&lt;p&gt;Negative Comments Sample:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;range&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;{}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;negatives&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Our health plan has covered my psychotherapy and my antidepressant medication. My manager has been aware but discreet throughout. I did get negative reviews when my depression was trashing my delivery but y&amp;rsquo;know I wasn&amp;rsquo;t delivering.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;In addition to my own mental health issues I&amp;rsquo;ve known several coworkers that may be suffering and I don&amp;rsquo;t know how to tell them I empathize and that I want to help.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;In my previous workplace which had mental health protections policies and access to counsellors my Director went so far as to say to me in somewhat casual conversation A woman was murdered across the street. At best though she was bipolar and at worst - who knowsI have bipolar disorder. I have zero faith that an organization with policies in place could appropriately handle mental health. I have even less faith that a workplace without the policies in place could appropriately handle mental health. I can only imagine it&amp;rsquo;s worse in full tech environments.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Positive Comments Sample:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;range&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;{}&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\n&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;positives&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;i&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I have chronic low-level neurological issues that have mental health side effects. One of my supervisors has also experienced similar neurological problems so I feel more comfortable being open about my issues than I would with someone without that experience.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Sometimes I think  about using drugs for my mental health issues. If i use drugs I feel better&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I selected my current employer based on its policies about self care and the quality of their overall health and wellness benefits. I still have residual caution from previous employers who ranged from ambivalent to indifferent to actively hostile regarding mental health concerns.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;From the samples, we can observe some genuinely positive and negative sentiments from the comments. These can be further analyzed to gain deeper insights.&lt;/p&gt;&#xA;&lt;p&gt;To wrap up this step, we&amp;rsquo;ll identify common themes or keywords in the negative and positive comments:&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;step-6-finding-common-themes&#34;&gt;Step 6: Finding Common Themes&lt;/h2&gt;&#xA;&lt;p&gt;To derive more value from the comments, let&amp;rsquo;s identify the most recurrent themes or issues. This can help in understanding common pain points or positive aspects that respondents are talking about.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;most_common&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;top_n&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;all_words&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;processed_comments&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;split&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;not&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;string&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;punctuation&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;word_counts&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;Counter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;all_words&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;top_10_words&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;word_counts&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;most_common&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;top_n&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;top_10_words&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This helper function calculates the top 10 words from the &amp;lsquo;processed_comments&amp;rsquo; column.&lt;/p&gt;&#xA;&lt;p&gt;Now, let&amp;rsquo;s run the above function for both negative and positive dataframes:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;most_common&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;negatives_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;[(&amp;lsquo;health&amp;rsquo;, 45), (&amp;lsquo;mental&amp;rsquo;, 41), (&amp;lsquo;issue&amp;rsquo;, 22), (&amp;rsquo;employer&amp;rsquo;, 21), (&amp;lsquo;depression&amp;rsquo;, 20), (&amp;lsquo;work&amp;rsquo;, 19), (&amp;lsquo;would&amp;rsquo;, 15), (&amp;lsquo;bad&amp;rsquo;, 12), (&amp;lsquo;people&amp;rsquo;, 12), (&amp;lsquo;insurance&amp;rsquo;, 12)]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;most_common&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;positives_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&#xA;&lt;p&gt;[(&amp;lsquo;health&amp;rsquo;, 63), (&amp;lsquo;mental&amp;rsquo;, 55), (&amp;lsquo;work&amp;rsquo;, 36), (&amp;lsquo;issue&amp;rsquo;, 30), (&amp;rsquo;employer&amp;rsquo;, 26), (&amp;lsquo;company&amp;rsquo;, 25), (&amp;lsquo;would&amp;rsquo;, 21), (&amp;lsquo;know&amp;rsquo;, 17), (&amp;lsquo;people&amp;rsquo;, 17), (&amp;lsquo;get&amp;rsquo;, 15)]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;It&amp;rsquo;s evident that &amp;lsquo;health&amp;rsquo; and &amp;lsquo;mental&amp;rsquo; are dominant themes in both negative and positive comments. This is expected given the context of the dataset. For the negative comments, other notable themes include &amp;rsquo;employer&amp;rsquo;, &amp;lsquo;depression&amp;rsquo;, and &amp;lsquo;insurance&amp;rsquo;. Understanding these themes can provide actionable insights for organizations looking to address specific concerns.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;resources&#34;&gt;Resources&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/lukastymo/lukastymo.com-resources/blob/master/002-how-pandas-can-help/pandas_showcase.ipynb&#34;&gt;Full notebook supporting this post&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.kaggle.com/datasets/osmi/mental-health-in-tech-survey&#34;&gt;Kaggle dataset&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Basics of Data Manipulation in Python</title>
      <link>https://lukastymo.com/posts/017-ds-data-manipulation/</link>
      <pubDate>Wed, 31 May 2023 10:22:51 +0200</pubDate>
      <guid>https://lukastymo.com/posts/017-ds-data-manipulation/</guid>
      <description>&lt;p&gt;In this post, we learn the basics of data manipulation in Python. We&amp;rsquo;ll use the following:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Regular Expressions&lt;/li&gt;&#xA;&lt;li&gt;Numpy&lt;/li&gt;&#xA;&lt;li&gt;Pandas&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;regular-expression&#34;&gt;Regular Expression&lt;/h2&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start from this string and basic imports:&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;In this post, we learn the basics of data manipulation in Python. We&amp;rsquo;ll use the following:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Regular Expressions&lt;/li&gt;&#xA;&lt;li&gt;Numpy&lt;/li&gt;&#xA;&lt;li&gt;Pandas&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;regular-expression&#34;&gt;Regular Expression&lt;/h2&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start from this string and basic imports:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;re&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;str&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Hello, World. It&amp;#39;s me, Python.&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we can use regular expressions to get what we&amp;rsquo;re looking for. For example, we want all words which start from capital letter are of size at least 2:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;pattern&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;sa&#34;&gt;r&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;[A-Z]\w+&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;re&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;findall&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pattern&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;, &lt;span class=&#34;s1&#34;&gt;&amp;#39;World&amp;#39;&lt;/span&gt;, &lt;span class=&#34;s1&#34;&gt;&amp;#39;It&amp;#39;&lt;/span&gt;, &lt;span class=&#34;s1&#34;&gt;&amp;#39;Python&amp;#39;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Listing:&lt;/p&gt;&#xA;&lt;p&gt;1: &lt;code&gt;r&#39;[A-Z]\w+&#39;&lt;/code&gt; - r indicates to Python it&amp;rsquo;s not a normal string. Otherwise, it would treat &lt;code&gt;\&lt;/code&gt; as a special character, like &lt;code&gt;\n&lt;/code&gt; - a new line,&#xA;which wouldn&amp;rsquo;t be what we want here, as regexp uses them to indicate special meaning, e.g. &lt;code&gt;\w&lt;/code&gt; - word character. Next, &lt;code&gt;[A-Z]&lt;/code&gt; means that&#xA;the first letter should be between A - Z, and lastly, &lt;code&gt;+&lt;/code&gt; means we want at least one-word character, which together with the first letter give us at least 2 size (asked in the question)&lt;/p&gt;&#xA;&lt;p&gt;2: Once we have the pattern, we need to apply it to the string. &lt;code&gt;findall&lt;/code&gt; gives us a list of all matches.&lt;/p&gt;&#xA;&lt;p&gt;To learn more about regular expression, we can check the well-written documentation: &lt;a href=&#34;https://docs.python.org/3/library/re.html&#34;&gt;https://docs.python.org/3/library/re.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;To create complicated regexp, sometimes we want to experiment with them on our test. We can do this, for example here: &lt;a href=&#34;https://regex101.com/&#34;&gt;https://regex101.com/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Even though regexp has a bad press, it may be helpful when we start data preparation.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;numpy&#34;&gt;NumPy&lt;/h2&gt;&#xA;&lt;p&gt;NumPy is a library for scientific computing. It helps in working in large, multi-dimensional arrays and matrices. It also comes with a lot of mathematical functions.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s see it in action:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;numpy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;np&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;lt;class &lt;span class=&#34;s1&#34;&gt;&amp;#39;list&amp;#39;&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&amp;lt;class &lt;span class=&#34;s1&#34;&gt;&amp;#39;numpy.ndarray&amp;#39;&lt;/span&gt;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;list&lt;/code&gt; is a basic type in Python. It&amp;rsquo;s very good but has some limitations. Especially in numerical and matrix operations. For example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;1, 2, 3, 4, 5, 6&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Oh no, interpreting our lists as vectors don&amp;rsquo;t seem right. Adding two vectors here should be &lt;code&gt;[5, 7, 9]&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;As we would like to use lots of matrices and vectors and have different mathematical operations, different types must be introduced.&lt;/p&gt;&#xA;&lt;p&gt;Meet &lt;code&gt;ndarray&lt;/code&gt;, which gives you a variety of math functions. Additionally, &lt;code&gt;ndarray&lt;/code&gt; is statically typed. The type is known&#xA;on the creation of the array, whereas with lists, we can keep different types: &lt;code&gt;my_list = [1, &#39;hello&#39;, 3.14]&lt;/code&gt;.  We say that &lt;code&gt;ndarray&lt;/code&gt; is homogeneous.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;5, 7, 9&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can do much better:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;zeros&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;zeros&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;((&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rand&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;random&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;values&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;9&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linspace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.25&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.75&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;1.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rand&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;random&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and vector operations:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rand&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;rand&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;element&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;wise&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;addition&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;element&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;wise&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;subtraction&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;element&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;wise&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;modulo&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;element&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;wise&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;multiplication&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;@&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dot&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;product&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where dot product is defined as:&#xA;$$&#xA;\mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{n} a_i b_i&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;pandas&#34;&gt;Pandas&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;series&#34;&gt;Series&lt;/h3&gt;&#xA;&lt;p&gt;Pandas, another common library in data science, is built on top of Numpy. It gives us a lot of useful functions for data manipulation.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;Series&lt;/code&gt;, is one-dimensional &lt;code&gt;ndarray&lt;/code&gt; with axis labels:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pandas&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pd&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;pd&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Series&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Alice&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Bob&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Molly&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;    Alice&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;     Bob&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;    Molly&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;dtype: object&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Initially, I was confused by this type, as it looks exactly like an array. The key here comes with the labels,&#xA;which may not only be ints but any type, for example, &lt;code&gt;string&lt;/code&gt; or &lt;code&gt;datetime&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pd&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;Series&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s1&#34;&gt;&amp;#39;AAA&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Alice&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;s1&#34;&gt;&amp;#39;BBB&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Bob&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;s1&#34;&gt;&amp;#39;CCC&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Molly&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;iloc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;s&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;loc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;BBB&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Bob&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Bob&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;7-8: &lt;code&gt;iloc&lt;/code&gt; integer location index - returns as a row by numeric index, whereas &lt;code&gt;loc&lt;/code&gt; label-based index returns a row by a label.&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;dataframe&#34;&gt;DataFrame&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pd&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;DataFrame&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;({&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s1&#34;&gt;&amp;#39;A&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s1&#34;&gt;&amp;#39;B&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s1&#34;&gt;&amp;#39;C&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;8&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;9&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;   A  B  C&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;4&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;7&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;8&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;6&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;9&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Series was one dimensional labelled array, and DataFrame is a two-dimensional labelled array. It&amp;rsquo;s like a table in SQL or Excel.&lt;/p&gt;&#xA;&lt;p&gt;And just like SQL, it provides a lot of useful functions: groupby, join, merge, etc.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s do some practice in DataFrame. For this, I will use Finance Data from Kaggle: &lt;a href=&#34;https://www.kaggle.com/datasets/nitindatta/finance-data?resource=download&#34;&gt;https://www.kaggle.com/datasets/nitindatta/finance-data?resource=download&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Read the data:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pandas&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;pd&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;plt&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;pd&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;read_csv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Finance_data.csv&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;your&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;path&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;the&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;csv&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Group and narrow does amount of columns:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;gender&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;Mutual_Funds&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;groupby&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;gender&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;count&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Female,15&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Male,25&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s leave only records which have Mutual Funds (and show the first 10 rows):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Mutual_Funds&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;head&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;what about drawing a plot, let&amp;rsquo;s say a gender distribution:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;groupby&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;gender&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;age&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;plot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;kind&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;kde&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;xlabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Age&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;legend&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;show&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/017/01_gender.png&#34; alt=&#34;Gender distribution&#34;&gt;&lt;/p&gt;&#xA;</content:encoded>
    </item>
    <item>
      <title>Math Methods in Data Science</title>
      <link>https://lukastymo.com/posts/018-ds-math_methods/</link>
      <pubDate>Tue, 30 May 2023 07:45:37 +0200</pubDate>
      <guid>https://lukastymo.com/posts/018-ds-math_methods/</guid>
      <description>&lt;p&gt;In Data Science, understanding some math is essential. Let&amp;rsquo;s review some essential math methods in Python grouped in:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Basics&lt;/li&gt;&#xA;&lt;li&gt;Linear Algebra&lt;/li&gt;&#xA;&lt;li&gt;Probability&lt;/li&gt;&#xA;&lt;li&gt;Statistics&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;basics&#34;&gt;Basics&lt;/h2&gt;&#xA;&lt;p&gt;Basic operations on sets&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set(range(1, 10)) // a set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 = {x for x in range(1, 10) if x % 2 == 0} // another set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod3 = {x for x in range(1, 10) if x % 3 == 0} // yet another set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 | mod3 // union&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 &amp;amp; mod3 // intersection&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 - mod3 // difference&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Solving Functions in python are done with &lt;strong&gt;sympy&lt;/strong&gt;&lt;/p&gt;</description>
      <content:encoded>&lt;p&gt;In Data Science, understanding some math is essential. Let&amp;rsquo;s review some essential math methods in Python grouped in:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Basics&lt;/li&gt;&#xA;&lt;li&gt;Linear Algebra&lt;/li&gt;&#xA;&lt;li&gt;Probability&lt;/li&gt;&#xA;&lt;li&gt;Statistics&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2 id=&#34;basics&#34;&gt;Basics&lt;/h2&gt;&#xA;&lt;p&gt;Basic operations on sets&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set(range(1, 10)) // a set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 = {x for x in range(1, 10) if x % 2 == 0} // another set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod3 = {x for x in range(1, 10) if x % 3 == 0} // yet another set&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 | mod3 // union&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 &amp;amp; mod3 // intersection&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mod2 - mod3 // difference&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Solving Functions in python are done with &lt;strong&gt;sympy&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;sympy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;sp&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;symbols&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;x&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;diff&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;first&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;derivative&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;of&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;with&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;respect&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dy&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;/&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dx&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;solve&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;solve&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s take more complicated functions and plot it&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;**&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;plot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/018/plot1.png&#34; alt=&#34;plot of a function&#34;&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df_dx&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;diff&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df_dx&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;2x+3&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now, we can calculate the value in a x=2 point of the derivative:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;df_dx&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;evalf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subs&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;})&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or find zeros of the derivative:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sp&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;solve&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;df_dx&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;[-3/2]&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;linear-algebra&#34;&gt;Linear Algebra&lt;/h2&gt;&#xA;&lt;p&gt;Numpy provies a lot of methods for linear algebra. They are defined in &lt;code&gt;np.linalg&lt;/code&gt; module.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s define some vectors:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;numpy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;np&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;20&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;30&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;40&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;50&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;w&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;array&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;vector&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are a few important concepts with vectors and matrices. Firstly, let&amp;rsquo;s understand the definition and then see how we can calculate it in Python.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;linear combination - a linear combination of vectors v1, v2, &amp;hellip;, vn is any vector of the form a1v1 + a2v2 + &amp;hellip; + anvn, where a1, a2, &amp;hellip;, an are scalars&lt;/li&gt;&#xA;&lt;li&gt;span - the span of a set of vectors is the set of all their linear combinations&lt;/li&gt;&#xA;&lt;li&gt;basis - a basis of a vector space is a set of vectors that are linearly independent and that span the vector space&lt;/li&gt;&#xA;&lt;li&gt;linear independence - a set of vectors is linearly independent if no vector in the set is a linear combination of the other vectors in the set&lt;/li&gt;&#xA;&lt;li&gt;rank of a matrix - the maximum number of linearly independent column vectors in the matrix&lt;/li&gt;&#xA;&lt;li&gt;dot product - the dot product of two vectors is the sum of the products of the corresponding entries of the two sequences of numbers&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linalg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;matrix_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rank&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;of&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;w&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;dot&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;product&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;w&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;w&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;w&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;element&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;wise&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;multiplication&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and operations on some matrices&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;randn&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;shape&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;(3, 4)&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Check linear independence:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;rank&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linalg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;matrix_rank&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;is_linear_independence&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rank&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;==&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;shape&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;is_linear_independence&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;True&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Matrix operations:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;randn&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;randn&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;multiplication&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;@&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;or&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;multiplication&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linalg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;det&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;determinant&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linalg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;inv&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;matrix&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;inverse&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lastly, we see how we can find eigenvalues and eigenvectors.&lt;/p&gt;&#xA;&lt;p&gt;A scalar &lt;strong&gt;λ&lt;/strong&gt; is called an eigenvalue of a matrix A if there is a non-zero vector x such that Ax = λx.&#xA;Such a vector x is called an &lt;strong&gt;eigenvector&lt;/strong&gt; corresponding to &lt;strong&gt;λ&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;eigvalues&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eigvectors&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linalg&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;eig&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;C&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eigenvalues&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;and&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eigenvectors&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h2 id=&#34;probability&#34;&gt;Probability&lt;/h2&gt;&#xA;&lt;p&gt;To play with probability we need to import &lt;code&gt;scipy.stats&lt;/code&gt; module, and few more:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scipy.stats&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;norm&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;from&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scipy.stats&lt;/span&gt; &lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rv_discrete&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;numpy&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;np&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;plt&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can define a very simple random variable:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;randint&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;define&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;random&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;variable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;between&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;100&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s define few concepts:&lt;/p&gt;&#xA;&lt;p&gt;probability mass function - a function that gives the probability that a discrete random variable is exactly equal to some value&lt;/p&gt;&#xA;&lt;p&gt;Discrete distribution:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;P_x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;rv_discrete&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;X&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;values&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;P_x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pmf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;probability&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mass&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;function&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;array([0.1, 0.4, 0.3, 0.1, 0.1])&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s plot it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fig&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subplots&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;plot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;ro&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ms&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;12&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;mec&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;r&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;vlines&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;colors&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;r&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lw&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Discrete Distribution&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/018/plot2.png&#34; alt=&#34;plot of a probability mass function&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;Similarly, for continous distribution:&lt;/p&gt;&#xA;&lt;p&gt;probability dense function - a function that gives the probability that a continuous random variable would have exactly the value x&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;std_dev&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;norm&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;loc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;std_dev&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;define&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;normal&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;distribution&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;std_dev&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;linspace&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;std_dev&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;std_dev&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;y&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;pdf&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And plot it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fig&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subplots&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;plot&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;r-&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lw&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.6&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;label&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;norm pdf&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;fill_between&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;x&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;y&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;color&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;r&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;Normal Distribution (mean=0, std_dev=1&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://lukastymo.com/images/posts/018/plot3.png&#34; alt=&#34;plot of a probability dense function&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;To calculate expected values, variance, conditional probability and Bayes&amp;rsquo; rule:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;expected&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;X&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;var&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;//&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;variance&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;choice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;choice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;False&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;],&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_a_and_b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;A&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;B&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_a_given_b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_a_and_b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_a_given_b&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&#xA;&lt;code&gt;0.7499999999999999&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Bayes&amp;rsquo; rule - a way to calculate conditional probability. It is named after Thomas Bayes, who first showed how it worked.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;bayes_rule&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p_b_given_a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;):&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_b_given_a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_b_given_a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.5&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_a&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;bayes_rule&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p_b_given_a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_a&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_b&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output: &lt;code&gt;0.125&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;statistics&#34;&gt;Statistics&lt;/h2&gt;&#xA;&#xA;&lt;h3 id=&#34;central-limit-theorem&#34;&gt;Central Limit Theorem&lt;/h3&gt;&#xA;&lt;p&gt;Central Limit Theorem - the sum of a large number of independent random variables will be approximately normally distributed&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s check this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;num_samples&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;10000&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;500&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Population with non normal distribution&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;population&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;uniform&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;low&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;high&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;10&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1_000_000&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Take &amp;#39;num_samples&amp;#39; samples of size &amp;#39;sample_size&amp;#39; from the population&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;samples&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;choice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;population&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;num_samples&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sample_size&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sample_means&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;samples&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;axis&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;sample_means&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;array([4.9086697 , 4.82018441, 4.78162058, ..., 4.90335171, 5.09722832, 5.02062739])&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;And plot it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;fig&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ax1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;ax2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;subplots&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;figsize&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;14&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;population&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bins&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;30&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;density&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;color&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;red&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Original Population Distribution&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_xlabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Value&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax1&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_ylabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Density&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hist&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sample_means&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bins&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;30&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;density&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;True&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;color&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;green&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;0.7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Distribution of Sample Means&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_xlabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Sample Mean&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;ax2&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;set_ylabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Density&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;plt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;show&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&#xA;&lt;img src=&#34;https://lukastymo.com/images/posts/018/plot4.png&#34; alt=&#34;plot of the Central Limit Theorem&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see taking lots of samples from a non-normal distribution and calculating the mean of each sample, we get a normal distribution!&lt;/p&gt;&#xA;&#xA;&lt;h3 id=&#34;hypothesis-testing&#34;&gt;Hypothesis Testing&lt;/h3&gt;&#xA;&lt;p&gt;Hypothesis testing - a way to test whether a sample is likely to have come from a particular population.&lt;/p&gt;&#xA;&lt;p&gt;In a two-sample t-test the null hypothesis is that the means of both groups are the same. If the p-value is less than the significance level, then we can reject the null hypothesis.&lt;/p&gt;&#xA;&lt;p&gt;Rejecting a hypothesis means that we found statistically significant evidence to say that the means of two populations are different.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kn&#34;&gt;import&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;scipy.stats&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;as&lt;/span&gt; &lt;span class=&#34;nn&#34;&gt;stats&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;group1&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;normal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;loc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;5.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;1.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;30&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;group2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;np&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;random&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;normal&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;loc&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;6.0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;scale&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mf&#34;&gt;1.5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;30&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;mf&#34;&gt;0.05&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;t_stat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stats&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ttest_ind&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;group1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;group2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;t_stat&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;p_value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;p_value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alpha&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Reject null hypothesis&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;nb&#34;&gt;print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Fail to reject null hypothesis&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Output:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-plaintext&#34; data-lang=&#34;plaintext&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;-2.096984052240135&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;0.04036532774839232&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Reject null hypothesis&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Rejected as expected. There are different as we have selected different mean and standard deviation.&lt;/p&gt;&#xA;</content:encoded>
    </item>
  </channel>
</rss>
