The problem is this: consider the three inputs A, B, C, find a logic circuit with the logical elements AND, OR, and NOT, so that the output is not (A), not (B), not (C), using most 2 NOT the gate.
I would like to find a prolog scheme. My idea is to compute the predicate "available", which takes a function and says if it exists, which evaluates f.
I have the following predicates:
not([],[]). not([H|T],[G|S]) :- G #=# 1-H, not(T,S). or([],[],[]). or([0|T],[0|S],[0|R]) :- or(T,S,R). or([1|T],[0|S],[1|R]) :- or(T,S,R). or([1|T],[1|S],[1|R]) :- or(T,S,R). or([0|T],[1|S],[1|R]) :- or(T,S,R). and([],[],[]). and([1|T],[1|S],[1|R]) :- and(T,S,R). and([0|T],[1|S],[0|R]) :- and(T,S,R). and([1|T],[0|S],[0|R]) :- and(T,S,R). and([0|T],[0|S],[0|R]) :- and(T,S,R). accessible(_,_,0) :- !,fail. accessible([0,1,0,1,0,1,0,1],[12],_) :- !. accessible([0,0,1,1,0,0,1,1],[11],_) :- !. accessible([0,0,0,0,1,1,1,1],[10],_) :- !. accessible(F,L,C) :- CC is C-1, or(G,H,F), accessible(G,M,CC), accessible(H,N,CC), L=[0, [M,N]]. accessible(F,L,C) :- CC is C-1, and(G,H,F), accessible(G,M,CC), accessible(H,N,CC), L=[1,[M,N]]. accessible(F,L,C) :- CC is C-1, not(F,X), accessible(X,M,CC), L=[2,M].
I would like to compute the xor function between 11,12, so I try the following goal: available ([0,1,1,0,0,1,1,0], X, 4).
But the prologue works for a while before getting a good answer. I would like to know how to improve the program to make it faster.
PS How to print a string without ASCII codes using the GNU prolog?