# Prolog Cookbook

1. Documenting, testing, and moduling
2. Classical Logic
1. Negation
2. Conjunction
3. Disjunction
4. Implication
5. Equivalence
3. Automata
4. Graph Traversal
5. Route Finding
6. Puzzle Solving

# Series

By Robert Laing

## Flow Control

Yet another way to think of logic is as electrical switches, where on is true and off is false. Here conjunction is switches in series, and disjunction is switches in parallel.

If any switch in series is not on (such as switch r in the above diagram), it breaks the flow of electric current, meaning a light or whatever the circuit powers would be off. If the switches were in parallel, (which I’ll illustrate in disjunction), any on switch would put the circuit on.

Looking at the above four switches in series — p ∧ q ∧ r ∧ s — does it make any difference what order they are in?

From the perspective of pure maths, that’s a stupid question: p ∧ q is commutative and associative, just like multiplication.

But something Prolog makes explicit by using a comma for both and and to separate sequential statements, in some cases the order does matter.