Logic Programming
What
versus
How
 

Example - Digital Circuits


A digital circuit is a collection of interconnected digital components called gates. Gates have inputs and outputs. When Boolean signals (on or off) are applied to the inputs of a gate, the circuit produces a corresponding output depending on the type of the gate. The output of an and-gate is on if and only if both inputs are on. The output of an or-gate is on if and only if at least one of the inputs is on. The output of an xor-gate is on if and only if the inputs disagree.

The following illustration is a schematic diagram for a digital circuit called a full adder. There are three input nodes (the boxes labelled x, y, and z), three internal nodes (the boxes labelled a, b, and o), and two output nodes (the boxes labelled s and c). There are two xor-gates (the components at the top), two and-gates (the components on the lower left), and one or-gate (the component on the lower right).

x y o z a b s c
Click on x, y, z to toggle their values.

Given the boolean nature of signals on nodes and the deterministic character of gates, it is quite natural to model digital circuits as a logic program. We can represent each node of a circuit as a factoid, with the idea that the a node is on if the factoid is true and off if the factoid if false. With this convention, we can capture the behavior of gates by writing view definitions for the the values the intermediate and output nodes in terms of the input nodes.