Skip to content

Instantly share code, notes, and snippets.

@jarble
Created May 29, 2022 22:01
Show Gist options
  • Save jarble/15bb4093a7aa83eca03230a77a7206e8 to your computer and use it in GitHub Desktop.
Save jarble/15bb4093a7aa83eca03230a77a7206e8 to your computer and use it in GitHub Desktop.
An implementation of three-valued logic in Prolog
:- initialization(main).
main :-
three_valued_logic(((true,false);unknown),Result),
writeln(Result).
three_valued_logic(true,true).
three_valued_logic(false,false).
three_valued_logic(unknown,unknown).
three_valued_logic(not(A),false) :-
three_valued_logic(A,true).
three_valued_logic(not(A),true) :-
three_valued_logic(A,false).
three_valued_logic(not(A),unknown):-
three_valued_logic(A,unknown).
three_valued_logic((A,B),true) :-
three_valued_logic([A,B],[A1,B1]),
(A1==true;B1==true).
three_valued_logic((A,B),false) :-
three_valued_logic([A,B],[A1,B1]),
(A1==false;B1==false).
three_valued_logic((A,B),unknown) :-
three_valued_logic([A,B],[A1,B1]),
(A1==unknown;B1==unknown).
three_valued_logic((A;B),unknown) :-
three_valued_logic([A,B],[A1,B1]),
(A1==unknown;B1==unknown),(A1==false;B1==false).
three_valued_logic((A;B),false) :-
three_valued_logic([A,B],[A1,B1]),
(A1==false,B1==false).
three_valued_logic((A;B),true) :-
three_valued_logic([A,B],[A1,B1]),
(A1==true;B1==true).
three_valued_logic([],[]).
three_valued_logic([A|B],[A1|B1]) :-
three_valued_logic(A,A1),three_valued_logic(B,B1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment