1 /**
2  * Last modified: Aug 05 2004
3  *
4  * @author Takayuki Hoshi <hoshi103@chapman.edu>
5  * File: SystemLP.java
6  *
7 System: Logic of Paradox ( LP)
8 
9  * TV = { 0, u, 1 } = { 0, 2, 1}
10  * D = { 1, 2 }
11  * C = { ~, &, |, =>, <=> }
12  *
13  * Here, LP interprets `2' as "both true and false"; 1 as "true and true only";
14  * and 0 as "false and false only".
15  */
16 
17 /* Note that in this class, we are assuming that the truth value passed to each
18  * function is necessarily either 0, 1 or 2.  */
19 public class SystemLP {
20 
21 /*
22  * Translates a truth value to english
23  */
truthValueToEnglish( int a )24 	public static String truthValueToEnglish( int a ) {
25 		/* 1 -> True, 0 -> False CONVERSION */
26 		if (a == 0) {
27 			return "False" ;
28 		}
29 		else if ( a == 1 ) {
30 			return "True" ;
31 		}
32 		else		// !! this is the change (from K3)
33 			return "True" ;
34 // 		else return "Unsupported truth value found in the formula." ;
35 	}
36 
37 /*
38  * [ ~x ]
39  */
interpretNot( int x )40 		public static int interpretNot( int x ) {
41 			if ( x == 1 ) return 0;
42 			else if ( x == 0 ) return 1;
43 			else return 2;
44 		}
45 
46 /*
47  * [ x & y ]
48  */
49 
interpretAnd( int x, int y )50 		public static int interpretAnd( int x, int y ) {
51 			if ( x == 1 &&  y == 1 ) return 1;
52 			else if ( x == 0 || y == 0) return 0;
53 			else return 2;
54 		}
55 
56 
57 /*
58  * [ x | y ]
59  */
interpretOr( int x, int y )60 		public static int interpretOr( int x, int y ) {
61 			if ( x == 0 &&  y == 0 ) return 0;
62 			else if ( x == 1 || y == 1) return 1;
63 			else return 2;
64 		}
65 
66 /*
67  * [ x => y ]
68  */
interpretImplies( int x, int y )69 		public static int interpretImplies( int x, int y ) {
70 			if ( x == 0 || y == 1) return 1;
71 			else if ( x == 1 && y == 0 ) return 0;
72 			else return 2;
73 		}
74 
75 /*
76  * [ x <=> y ]
77  */
interpretIff( int x, int y )78 		public static int interpretIff( int x, int y ) {
79 			return
80 				interpretAnd (
81 					interpretImplies( x, y ), interpretImplies( y, x ) );
82 		}
83 
84 }		// end of class `SystemLP'
85