The Curated Daily
← Back to the archiveDispatch · 6 min read
Dispatch

Prolog Basics Explained with Pokémon

By the editors·Monday, May 18, 2026·6 min read
A person holds a handheld gaming device outdoors with Pokémon Legends on screen.
Photograph by Daniel J. Schwarz · Pexels

Imagine you're a Pokémon trainer, strategizing your next battle. You don't just hope for the best; you analyze your Pokémon’s strengths, your opponent's weaknesses, and formulate a plan. This strategic thinking, based on rules and facts, is surprisingly similar to how Prolog, a powerful logic programming language, operates. And it’s this same logic that can be applied to sophisticated financial decision-making.

This article will introduce you to the basics of Prolog, not through dry academic examples, but through the vibrant world of Pokémon. We’ll then tie these concepts to real-world finance applications, showing you how you can use Prolog to automate aspects of investment, risk management, and more. It might seem like a leap, but trust us – you'll see the connection!

What is Prolog? A Different Way to Program

Most programming languages (like Python, Java, or C++) are imperative. You tell the computer how to solve a problem, step-by-step. Prolog is declarative. You tell the computer what is true, and Prolog figures out how to reach the desired conclusion.

Think of it this way:

  • Imperative (like giving directions): “Go straight for 2 miles, then turn left, then drive for 1 mile…”
  • Declarative (like asking a question): “How do I get to the stadium?”

Prolog excels at problems involving relationships, rules, and logical inference. This makes it exceptionally well-suited to financial modeling, where relationships between assets, risk factors, and market conditions are key. You define the rules, and Prolog finds the solutions.

Core Concepts: Facts, Rules, and Queries – The Pokémon Edition

Let's translate Prolog's core concepts using Pokémon.

Facts: Defining Our Pokémon World

Facts are statements that are considered true. In Prolog, facts are written as predicates. A predicate has a name and arguments. Let’s start simple:

```prolog

pokemon(pikachu). % Pikachu is a Pokémon. pokemon(charmander). % Charmander is a Pokémon. pokemon(squirtle). % Squirtle is a Pokémon.

type(pikachu, electric). % Pikachu is an Electric-type Pokémon. type(charmander, fire). % Charmander is a Fire-type Pokémon. type(squirtle, water). % Squirtle is a Water-type Pokémon.

weakness(electric, ground). % Electric types are weak against Ground types. weakness(fire, water). % Fire types are weak against Water types. weakness(water, electric). % Water types are weak against Electric types.

These are our basic facts. We're establishing the truth about Pokémon and their types. In finance, these facts could be things like:

  • asset(AAPL). – Apple is an asset.
  • risk(AAPL, moderate). – Apple has moderate risk.
  • returns(AAPL, 2023, 0.35). – Apple returned 35% in 2023.

Rules: Defining Relationships and Logic

Rules define relationships between facts. They say something is true if something else is true. Rules are written in the form: head :- body. (read as "head is true if body is true").

Let’s define a rule to determine if a Pokémon is strong against another Pokémon:

```prolog

strong_against(X, Y) :- type(X, TypeX), weakness(TypeX, Y).

This rule states: “X is strong against Y if X has a type (TypeX) and that type is weak against Y.”

Let's break this down:

  • strong_against(X, Y) is the head – what we're trying to prove.
  • type(X, TypeX), weakness(TypeX, Y) is the body – the conditions that must be true.
  • X and Y are variables.

In finance, rules could be:

  • profitable(Asset) :- returns(Asset, Year, Return), Return > 0.10. (An asset is profitable if its return in a given year is greater than 10%).
  • high_risk(Asset) :- risk(Asset, high). (An asset is high-risk if its risk level is high).

Queries: Asking Prolog Questions

Queries are questions you ask Prolog. Prolog will use its facts and rules to try and find an answer.

Let’s ask Prolog: "Is Pikachu strong against Squirtle?"

```prolog

?- strong_against(pikachu, squirtle).

Prolog will respond: true. because Pikachu is Electric-type, and Electric-type is weak against Water-type (Squirtle's type).

In finance, you could ask:

  • ?- profitable(AAPL). (Is Apple a profitable asset?)
  • ?- high_risk(Asset). (What assets are high-risk?) – Prolog would return all assets matching the rule.

A More Complex Pokémon Example: Super Effective Attacks

Let's create a more intricate example to showcase Prolog’s power. We'll define a rule to determine if an attack is "super effective" against a Pokémon:

```prolog

super_effective(Attack, Defender) :- type(Defender, DefenderType), attack_type(Attack, AttackType), weakness(AttackType, DefenderType).

attack_type(thunderbolt, electric). attack_type(ember, fire). attack_type(water_gun, water).

Now, if we query:

```prolog

?- super_effective(thunderbolt, squirtle).

Prolog will respond true. because Thunderbolt is an Electric-type attack, and Squirtle is a Water-type Pokémon, and Electric-type attacks are super effective against Water-type Pokémon.

Financial Applications of Prolog: Beyond Pokémon Battles

Now, let’s shift gears and explore how these Prolog concepts can be applied to finance.

1. Credit Scoring & Risk Assessment

Prolog can be used to build expert systems for credit scoring. You define rules based on various factors (income, debt, credit history, employment status) and Prolog can evaluate an applicant's risk profile. This allows for more nuanced and automated decisions than traditional scoring models.

2. Algorithmic Trading & Rule-Based Systems

You can create trading strategies based on complex market conditions. For example:

  • buy(Stock) :- price(Stock, CurrentPrice), indicator(Stock, RSI, Value), Value < 30. (Buy a stock if its RSI (Relative Strength Index) is below 30).
  • sell(Stock) :- price(Stock, CurrentPrice), indicator(Stock, MACD, Value), Value < 0. (Sell a stock if its MACD (Moving Average Convergence Divergence) is below 0).

Prolog will continuously monitor market data and execute trades based on these rules. https://example.com/ provides access to historical stock data APIs useful for this.

3. Fraud Detection

Prolog’s pattern-matching capabilities are ideal for identifying fraudulent transactions. You can define rules based on suspicious activity (large transactions, unusual locations, multiple transactions in a short period) and Prolog can flag potentially fraudulent activity for review.

4. Portfolio Optimization

While more complex optimization problems benefit from dedicated solvers, Prolog can handle simpler portfolio constraints and risk assessment rules. For example, ensuring a portfolio maintains a specific asset allocation or adheres to certain risk limits.

5. Regulatory Compliance

Financial institutions face a multitude of regulations. Prolog can be used to represent these regulations as rules and automatically check if transactions and processes comply with them.

Getting Started with Prolog: Resources and Tools

Ready to dive in? Here are some resources to get you started:

Conclusion: Logic is the Key

Prolog might seem daunting at first, but the underlying concepts are surprisingly intuitive, especially when framed in a relatable context like Pokémon. Its declarative nature makes it a powerful tool for automating complex financial decisions. By focusing on what you want to achieve, rather than how to achieve it, Prolog allows you to build elegant and efficient solutions to a wide range of financial problems. So, ditch the imperative mindset and embrace the power of logic!

Disclaimer:

This article contains affiliate links. If you purchase a product through these links, we may receive a small commission at no extra cost to you. This helps support the creation of valuable content like this. We only recommend products we believe in and that are relevant to our audience. The financial information provided in this article is for educational purposes only and should not be considered financial advice. Always consult with a qualified financial advisor before making any investment decisions.

Pass it onX·LinkedIn·Reddit·Email
The Sunday note

If this was your kind of read.

Sign up for the morning email — short, hand-written, and sent only when there's something worth your time.

Free, sent from a person, not a system. Unsubscribe in one click whenever.

Keep reading

The archive →