123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|390|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Misc Languages -> Monty Python - The Witch Trial

Tue, 15 Jul 2025, 15:45
Pixel_Outlaw

Monty Python - The Witch Trial


Since Prolog's domain is deduction (drawing conclusions from sparse details), I thought the famous witch trial scene from Monty Python and the Holy Grail would be fun.
It turns out, if we impose the rules from the movie into Prolog we can deduce that she is indeed a witch. (Despite the hat and false nose - but she has got a wart!)

To set the foundation, you simply state the facts in Prolog (a factbase) and it tries to unify facts you've set to deduce further facts.
Prolog is a mini world of details that you provide and it tries to "unify".
Prolog was an early AI language in France while Lisp was the choice for the US.
They are contemporaries of each other with Europe adopting both.

I never explicitly state that Martha is a witch but Prolog ferrets through the facts (given the movie's logic) discovering that she weighs as much as a duck and is made of wood. You can find more about Horn Clauses (the building block of Prolog).

What looks like functions are not. They're predicates and rules. You see no looping and no functions in the code below.
It is a world apart from Imperative Programming as we step into Logic Programming - its own paradigm.
Yet, in the background Prolog knows how to search and loop through everything to find "unification" (matches between rules and it's current world).

The bottom section in Emacs there is the "consultation" which is a live interrogation of Prolog's current world and it answering.
I load the source code and Prolog begins answering my questions.
This is not like SQL, it's actually deducing logic the whole way rather than just fetching details.
It has to back chain through various details in the tree of facts and match the ones that apply to answer my questions.
I specify no tables, no storage structure, nor control ONLY the facts from the movie!

Like the source, we only assert that she weighs the same as a duck.
Prolog from there discovers that she is made of wood, floats, and burns ... and therefore (you know the rest).