I am in my initial phase of writing code in Prolog and am still trying wrap my head around the paradigm so please pardon the primitiveness of this question.
I read in Wikipedia
A rule is of the form
Head :- Body.
and is read as "Head is true if Body is true".
That's simple enough. So I am building a knowledge base that simulates the functioning of a 1-bit adder.
In doing so, I am trying to create a rule for the following:
If there exists a gate X, and X is an AND gate, and X has a terminal going out of it, and that terminal has a signal and the signal is 0 THEN gate X must also have at least one input terminal that has a signal of 0.
As a Prolog rule, I wrote this to reflect my above sentence:
gate(X) /\ gate_type(X, and) /\ terminal(T, X, out) /\ signal(T, SIG) /\ (SIG is 0) :- (gate(X) /\ gate_type(X, and) /\ terminal_type(R, X, in) /\ signal(R, 0)).
To test my rule, I had a terminal t7
that is a terminal of an AND gate.
terminal_type(t7, a1, in).
gate_type(a1, and).
When I ask Prolog: signal(t7, 1), signal(t8, 1), signal(t9, X).
or anything like that, Mr. Prolog tells me
X = 1;
X = 0;
The answer I get should be only X = 1.