Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 46 ยท Logic and Knowledge Representation

Types of Reasoning in AI

Compare deductive, inductive, abductive, commonsense and non-monotonic reasoning with runnable Python, including default rules and a simple truth maintenance system.

Reasoning is the process of reaching conclusions from what you know. When people say a system "reasons", they can mean very different things. A theorem prover that derives a proof from axioms, a spam filter that generalises from examples and a doctor who guesses the most likely disease from symptoms are all reasoning, but in three different directions. Knowing which kind you need decides which algorithm to reach for.

This lesson separates the main kinds of reasoning, shows each one in a few lines of Python, and then tackles the problem that broke early logic-based AI: what happens when new information forces you to take back a conclusion. That is non-monotonic reasoning, and it is how an intelligent agent copes with a world where rules have exceptions.

Three directions of inference

Take a rule, a case and a result. Each style of reasoning fixes two of them and infers the third.

Style Given Infers Guaranteed true?
Deductive Rule + case Result Yes, if the premises are true
Inductive Many cases + results Rule No, only probable
Abductive Rule + result Most likely case (an explanation) No, only plausible

Consider the rule "all swans in this lake are white".

  • Deduction: this bird is a swan from this lake, so it is white.
  • Induction: every swan I have seen here is white, so all of them are white.
  • Abduction: this bird is white, and white birds here are usually swans, so it is probably a swan.
flowchart LR
    R["Rule"] --- D(("Deduction"))
    C["Case"] --- D
    D --> O["Result"]
    O2["Results seen"] --- I(("Induction"))
    C2["Cases seen"] --- I
    I --> R2["Rule"]
    R3["Rule"] --- A(("Abduction"))
    O3["Result seen"] --- A
    A --> C3["Best explanation"]

Deduction goes from the general to the specific, induction from the specific to the general, abduction from an effect back to its cause.

Deductive reasoning

Deduction is the kind of reasoning used by propositional and first-order logic. If the premises are true and the rules of inference are sound, the conclusion must be true. The classic pattern is modus ponens: from P and P -> Q, conclude Q. Another is modus tollens: from not Q and P -> Q, conclude not P.

Deduction adds no new information beyond what the premises already contain, but it makes it explicit, and it is the only style with a guarantee. It is the engine of theorem provers, rule-based systems and SQL-style queries (see Propositional Logic and Inference and Resolution).

Python Modus ponens and modus tollens

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last line shows the limit of deduction: knowing the ground is wet tells you nothing certain about rain. Going from effect to cause is abduction, the third style below.

Inductive reasoning

Induction generalises. From many observed cases it proposes a rule that covers them. This is the heart of machine learning: a decision tree, a regression line and a neural network are all inductive. The conclusion is never certain, because the next case may break the pattern (the famous black swan).

Even a few lines of code can induce a rule. The program below looks at labelled examples and keeps the single feature-value pair that best separates the classes.

Python Induce a rule from examples

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The rule is only as good as the examples. Add a few more rows (a flightless bird, a wingless ant) and the best rule changes, which is the point: induced knowledge is revisable. Large-scale versions of this idea appear in the machine-learning tracks of this site.

Abductive reasoning

Abduction is "inference to the best explanation". You see an effect and ask which cause would explain it best. Doctors, mechanics and debuggers do this all day: the engine will not start, so the battery is probably flat. Abduction is plausible, not certain, because several causes may explain the same effect.

A simple abductive engine scores each hypothesis by how many of the observations it explains and how likely it is a priori.

Python Abduction: the best explanation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With dim lights the flat battery wins easily. When the engine cranks, the battery hypothesis cannot account for the cranking and predicts symptoms that were not seen, so the empty tank takes over (wet plugs explain both observations too, but they are much less likely a priori). Abduction produces a ranked list of hypotheses to test, which is exactly how diagnostic systems use it. Bayesian networks (see Bayesian Networks) do the same job with proper probabilities.

Commonsense reasoning

Humans reason about the everyday world without noticing: a glass dropped on a tile floor probably breaks, you cannot put a bigger box inside a smaller one, ice melts when warm. Commonsense reasoning needs a huge background of such facts and the ability to apply them with context. It is hard for AI because:

  • the knowledge is vast and mostly unstated,
  • it depends on context (is "bank" a river bank or a money bank?),
  • it is full of exceptions, and
  • no complete dataset or rule base exists.

Projects such as Cyc spent decades hand-coding commonsense rules, and modern language models absorb a lot of it from text, but reliable commonsense reasoning is still an open problem. Everything in the next section is an attempt to make exceptions manageable.

Monotonic versus non-monotonic reasoning

Classical logic is monotonic: adding a new fact to the knowledge base can only add conclusions, never remove any. If bird(Tweety) and "birds fly" give you flies(Tweety), nothing you learn later can cancel it.

Real reasoning is non-monotonic. You believe Tweety flies until you learn that Tweety is a penguin, and then you retract. Most everyday rules are defaults: "birds fly" really means "birds normally fly, unless something says otherwise". Non-monotonic reasoning lets conclusions be withdrawn when new information arrives.

Monotonic Non-monotonic
New facts Only add conclusions May remove earlier conclusions
Rules Strict ("all birds fly") Defaults ("birds normally fly")
Typical formalisms Propositional and first-order logic Default logic, circumscription, closed-world assumption
Use Mathematics, proofs Commonsense, planning, databases
Python Default reasoning with retraction

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

After step 2 the conclusion flies disappears, even though a fact was added. That is non-monotonic behaviour in action. Step 4 shows the closed-world assumption used by databases and Prolog: anything not known to be true is treated as false. It is useful, and dangerous when the knowledge is incomplete.

Three families of formal systems handle this:

  • Default logic adds rules of the form "if bird(x) and it is consistent to assume flies(x), then conclude flies(x)."
  • Circumscription minimises the set of abnormal things: assume as few exceptions as possible.
  • Negation as failure (Prolog): not p holds if p cannot be proved.

Truth maintenance systems

If conclusions can be retracted, the program needs to know which other conclusions depended on them. A truth maintenance system (TMS) records, for every derived fact, the reasons that justify it. When a justification is removed, the TMS automatically withdraws everything that no longer has support.

Python A tiny truth maintenance system

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Retracting one premise silently removes two beliefs: flies loses its support, and so does everything built on it. Real TMS implementations also keep assumptions and detect contradictions, and they are used in planners, diagnosis tools and constraint solvers that need to back out of wrong guesses.

Choosing the right kind

You have You want Use
Axioms and a goal A guaranteed answer Deduction (logic, theorem proving)
Many examples A general rule or model Induction (machine learning)
Symptoms or effects The likely cause Abduction (diagnosis, Bayesian networks)
Rules with exceptions Revisable conclusions Non-monotonic reasoning, TMS
Uncertain evidence Graded belief Probability, fuzzy logic, belief functions

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A doctor sees a rash and fever and concludes measles is the most likely cause. Which kind of reasoning is this?

    Going from an observed effect to its most plausible cause is abduction, or inference to the best explanation.
  2. 2. Which kind of reasoning gives a conclusion that must be true if the premises are true?

    Deduction with sound inference rules is truth-preserving. Induction and abduction are only probable or plausible.
  3. 3. What makes reasoning non-monotonic?

    In a non-monotonic system a new fact (Tweety is a penguin) can invalidate a default conclusion (Tweety flies).
  4. 4. What does a truth maintenance system record?

    By storing the support for each fact, it can withdraw exactly the beliefs that lose their justification.
  5. 5. Which task is the classic use of induction?

    Induction generalises from specific cases to a general rule, which is what machine learning does.

Summary

  • Deduction (rule + case gives result) is certain; induction (cases give rule) and abduction (result gives cause) are only probable or plausible.
  • Modus ponens and modus tollens are the basic deductive moves.
  • Induction underlies machine learning; abduction underlies diagnosis.
  • Commonsense reasoning needs vast, contextual, exception-ridden knowledge and is still unsolved.
  • Monotonic logics never retract conclusions; non-monotonic ones use defaults, circumscription or negation as failure and allow retraction.
  • Truth maintenance systems track justifications so that retractions propagate correctly.

Next: Fuzzy Logic and Belief Functions.