i have been given functions and predicate to use to verify a 2 bit full adder circuit. This is what I have understood so far:-
a function signal(t) where t is terminal and signal takes value 1 or 0.
signal(T, V) :- V is 1; V is 0.
a function type(x) where type is a circuit element and type(x) can take value xor, and, or
type(X, T) :- T is and; T is or; T is xor.
a function out(x) denoting output at gate x and in(n, x) n is an input terminal.
out(X, O) :- type(X, and), O is I1+I2, in(1, X, I1), in(1, X, I2).
%%and so on for other gates
for gates predicates are given as
forall X[{type(X) == OR} ----> {(out(X) =1)}-----> for some y(in(y, X) = 1)]
For these I am not sure how to convert them to prolog code and do not understand how prolog functions return something (I think the result must also be provided as a parameter).
Any Help would be very useful !
First, you should select a better representation for your problems. Facts are enough for this porpouse. Circuits may be represented as:
in/1 --> input signal (0 or 1). this is required to avoid infinite loops (see later).
xor/2, and/2, or/2 --> logical operations over circuits A and B. not/1 --> etc.
This way, a circuit will take this shape:
Now, let's define a predicate output/1, which computes circuit's state:
This predeciate is reversible on porpouse, so inputs may be left as free variables in order to obtain all outputs:
output(A,B)should not be confused withoutput(in(A),B). The first may be instantiated to any circuit (infinite loop) while the second may be instatiated to just 0 or 1.It seems to work on recursive circuits: