-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathxor.pl
More file actions
24 lines (18 loc) · 764 Bytes
/
xor.pl
File metadata and controls
24 lines (18 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expressing XOR with 4 NAND gates.
Using universally quantified variables, you can use CLP(B)
constraints to show that the circuit computes XOR as intended.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- use_module(library(clpb)).
nand_gate(X, Y, Z) :- sat(Z =:= ~(X*Y)).
xor(X, Y, Z) :-
nand_gate(X, Y, T1),
nand_gate(X, T1, T2),
nand_gate(Y, T1, T3),
nand_gate(T2, T3, Z).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?- xor(X, Y, Z).
%@ sat(X=:=Y#Z).
?- xor(x, y, Z).
%@ sat(Z=:=x#y).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */