This content originally appeared on DEV Community and was authored by David Au Yeung
Introduction
When we talk about Artificial Intelligence (AI), the conversation often revolves around cutting-edge technologies like GPT, neural networks, or machine learning. But do you know where AI really began? The history of AI isn't just about Alan Turing and the Turing Test, it's also about rule-based systems and expert systems, the old-school AI that laid the foundation for modern advancements.
Before the era of deep learning, rule-based systems were the backbone of AI research. These systems were simple, interpretable, and precise, making them indispensable in fields like medicine, finance, and engineering. While they lack the "intelligence" of today's machine learning models, they excelled at emulating human reasoning by applying if-then rules to a knowledge base.
But what exactly are these systems? How do they work? And how can you build one in C#? In this article, we'll explore the fascinating history of old-school AI and guide you through creating your own rule-based expert system - a piece of AI history that's still relevant today.
Old-School AI: What Are Rule-Based and Expert Systems?
Rule-Based Systems
At their core, rule-based systems are AI models that rely on a set of predefined if-then rules to make decisions. These systems are deterministic and work by applying logical reasoning to a knowledge base of facts and rules.
A rule-based system typically consists of:
- Knowledge Base: Stores facts and rules in a structured format.
- Inference Engine: Applies rules to the facts to derive conclusions.
- User Interface: Allows users to input data and receive results.
Expert Systems
An expert system is a specialized type of rule-based system designed to mimic the decision-making ability of a human expert in a specific domain. Expert systems are used in areas where precision and interpretability are critical, such as:
- Diagnosing medical conditions.
- Troubleshooting technical issues.
- Providing legal or financial advice.
While modern AI systems rely on data-driven learning, expert systems leverage human knowledge encoded as logical rules. This makes them easy to understand and trustworthy, it is a key reason why they are still in use today.
Rule-Based Systems in Action: A C# Example
Let's start with a practical example: a loan evaluation system. This simple rule-based system determines whether a loan application should be approved or denied based on factors like income and credit score.
Example: Loan Evaluation System
using System;
using System.Collections.Generic;
namespace RuleBasedSystem
{
// Rule class
public class Rule
{
public Func<Dictionary<string, object>, bool> Condition { get; set; }
public Action<Dictionary<string, object>> Action { get; set; }
}
// Rule-Based System
public class RuleEngine
{
private readonly List<Rule> _rules = new List<Rule>();
public void AddRule(Func<Dictionary<string, object>, bool> condition, Action<Dictionary<string, object>> action)
{
_rules.Add(new Rule { Condition = condition, Action = action });
}
public void Evaluate(Dictionary<string, object> facts)
{
foreach (var rule in _rules)
{
if (rule.Condition(facts))
{
rule.Action(facts);
}
}
}
}
class Program
{
static void Main(string[] args)
{
// Create Rule Engine
var engine = new RuleEngine();
// Define rules
engine.AddRule(
facts => (int)facts["Income"] > 50000 && (int)facts["CreditScore"] > 700,
facts => facts["Decision"] = "Loan Approved"
);
engine.AddRule(
facts => (int)facts["Income"] <= 50000 || (int)facts["CreditScore"] <= 700,
facts => facts["Decision"] = "Loan Denied"
);
// Input facts
var facts = new Dictionary<string, object>
{
{ "Income", 55000 },
{ "CreditScore", 710 },
{ "Decision", "" }
};
// Evaluate rules
engine.Evaluate(facts);
// Output decision
Console.WriteLine($"Loan Decision: {facts["Decision"]}");
}
}
}
Result
Explanation
- Rules: The system checks predefined conditions (e.g., income and credit score thresholds) and applies the appropriate action.
- Facts: Input data is stored in a dictionary and updated based on rule evaluation.
- Deterministic Output: The same input will always produce the same output, ensuring reliability.
Expert Systems in Action: A C# Example
Now, let's build a more advanced expert system for medical diagnosis. This system takes symptoms as input and provides possible diagnoses.
Example: Medical Diagnosis Expert System
using System;
using System.Collections.Generic;
namespace ExpertSystem
{
// Rule class
public class DiagnosisRule
{
public Func<List<string>, bool> Condition { get; set; }
public string Diagnosis { get; set; }
}
// Expert System
public class ExpertSystem
{
private readonly List<DiagnosisRule> _rules = new List<DiagnosisRule>();
public void AddRule(Func<List<string>, bool> condition, string diagnosis)
{
_rules.Add(new DiagnosisRule { Condition = condition, Diagnosis = diagnosis });
}
public List<string> Infer(List<string> symptoms)
{
var diagnoses = new List<string>();
foreach (var rule in _rules)
{
if (rule.Condition(symptoms))
{
diagnoses.Add(rule.Diagnosis);
}
}
return diagnoses;
}
}
class Program
{
static void Main(string[] args)
{
// Create the expert system
var expertSystem = new ExpertSystem();
// Add rules
expertSystem.AddRule(
symptoms => symptoms.Contains("fever") && symptoms.Contains("cough"),
"You might have the flu."
);
expertSystem.AddRule(
symptoms => symptoms.Contains("headache") && symptoms.Contains("nausea"),
"You might have a migraine."
);
expertSystem.AddRule(
symptoms => symptoms.Contains("sore throat"),
"You might have a throat infection."
);
// Input symptoms
var symptoms = new List<string> { "fever", "cough" };
// Infer diagnoses
var diagnoses = expertSystem.Infer(symptoms);
// Output diagnoses
Console.WriteLine("Possible Diagnoses:");
foreach (var diagnosis in diagnoses)
{
Console.WriteLine($"- {diagnosis}");
}
}
}
}
Result
Explanation
- Rules: Each rule links a set of symptoms to a possible diagnosis.
- Inference: The system evaluates all rules and outputs matching diagnoses.
- Interactivity: Users can input symptoms, and the system provides human-like reasoning.
Applications of Rule-Based and Expert Systems
Rule-based and expert systems are still widely used in industries where interpretability and precision are critical. Examples include:
- Medical Diagnosis: Identifying illnesses based on symptoms.
- Troubleshooting: Providing solutions to technical problems (e.g., IT support systems).
- Finance: Loan approvals, fraud detection, and compliance checks.
- Legal: Automated legal advice and document analysis.
Why Learn About Old-School AI?
While modern AI systems like GPT dominate the headlines, old-school AI systems like rule-based and expert systems remain relevant and practical. They are:
- Simple: Easy to understand and implement.
- Explainable: Provide clear reasoning behind decisions.
- Reliable: Deterministic output ensures consistency.
By learning to build these systems, you gain a deeper understanding of how AI evolved and how logic-based reasoning complements data-driven approaches.
Conclusion
Rule-based and expert systems are the unsung heroes of AI history. They may not have the glamour of neural networks, but their precision, simplicity, and transparency make them indispensable tools in today's world. Whether you're diagnosing illnesses, evaluating loans, or troubleshooting systems, these old-school AI systems prove that sometimes, the simplest solutions are the most effective.
So, why not try building your own rule-based or expert system in C#? By doing so, you're not just learning to code, you're stepping into the rich history of AI itself.
Reference
Love C# & AI!
This content originally appeared on DEV Community and was authored by David Au Yeung

David Au Yeung | Sciencx (2025-10-13T16:07:20+00:00) Know the History of AI: Build Your Own Rule-Based Expert System in C#. Retrieved from https://www.scien.cx/2025/10/13/know-the-history-of-ai-build-your-own-rule-based-expert-system-in-c-2/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.