Inter4ql  5.2
Logic.h
1 #ifndef __LOGIC_H__
2 #define __LOGIC_H__
3 
4 #include <string>
5 #include "Types.h"
6 #include "Functions.h"
7 
8 namespace Inter4ql {
9 
10 
13  class Logic {
14  public:
22  if (a == b)
23  return a;
24  if (a == logic_type::TRUE && b == logic_type::FALSE
25  || b == logic_type::TRUE && a == logic_type::FALSE
26  || a == logic_type::INCONSISTENT
27  || b == logic_type::INCONSISTENT)
28  return logic_type::INCONSISTENT;
29  if (a == logic_type::UNKNOWN)
30  return b;
31  if (b == logic_type::UNKNOWN)
32  return a;
33  }
34 
42  if (a == b)
43  return a;
44 
45  if (a == logic_type::FALSE) {
46  return b;
47  }
48 
49  if (a == logic_type::UNKNOWN) {
50  if(b == logic_type::FALSE) return logic_type::UNKNOWN;
51  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
52  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
53  if(b == logic_type::TRUE) return logic_type::TRUE;
54  }
55 
56  if (a == logic_type::INCONSISTENT) {
57  if(b == logic_type::FALSE) return logic_type::INCONSISTENT;
58  if(b == logic_type::UNKNOWN) return logic_type::INCONSISTENT;
59  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
60  if(b == logic_type::TRUE) return logic_type::TRUE;
61  }
62 
63  if (a == logic_type::TRUE) {
64  return logic_type::TRUE;
65  }
66  }
67 
75  if (a == b)
76  return a;
77 
78  if (a == logic_type::FALSE) {
79  return logic_type::FALSE;
80  }
81 
82  if (a == logic_type::UNKNOWN) {
83  if(b == logic_type::FALSE) return logic_type::FALSE;
84  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
85  if(b == logic_type::INCONSISTENT) return logic_type::UNKNOWN;
86  if(b == logic_type::TRUE) return logic_type::UNKNOWN;
87  }
88 
89  if (a == logic_type::INCONSISTENT) {
90  if(b == logic_type::FALSE) return logic_type::FALSE;
91  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
92  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
93  if(b == logic_type::TRUE) return logic_type::INCONSISTENT;
94  }
95 
96  if (a == logic_type::TRUE) {
97  return b;
98  }
99  }
100 
108  // f < u < i < t
109 
110  if (a == logic_type::FALSE) {
111  return logic_type::TRUE;
112  }
113 
114  if (a == logic_type::UNKNOWN) {
115  if(b == logic_type::FALSE) return logic_type::UNKNOWN;
116  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
117  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
118  if(b == logic_type::TRUE) return logic_type::TRUE;
119  }
120 
121  if (a == logic_type::INCONSISTENT) {
122  if(b == logic_type::FALSE) return logic_type::INCONSISTENT;
123  if(b == logic_type::UNKNOWN) return logic_type::INCONSISTENT;
124  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
125  if(b == logic_type::TRUE) return logic_type::TRUE;
126  }
127 
128  if (a == logic_type::TRUE) {
129  if(b == logic_type::FALSE) return logic_type::FALSE;
130  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
131  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
132  if(b == logic_type::TRUE) return logic_type::TRUE;
133  }
134  }
135 
142  if (a == logic_type::TRUE) {
143  return logic_type::FALSE;
144  }
145 
146  if (a == logic_type::FALSE) {
147  return logic_type::TRUE;
148  }
149  return a;
150  }
151 
159  if (a == logic_type::TRUE || b == logic_type::TRUE) {
160  return logic_type::TRUE;
161  }
162 
163  if (a == logic_type::INCONSISTENT || b == logic_type::INCONSISTENT) {
164  return logic_type::INCONSISTENT;
165  }
166 
167  if (a == logic_type::UNKNOWN || b == logic_type::UNKNOWN) {
168  return logic_type::UNKNOWN;
169  }
170 
171  return logic_type::FALSE;
172  }
173 
181  if (a == logic_type::FALSE) {
182  return b;
183  }
184 
185  if (a == logic_type::UNKNOWN) {
186  if(b == logic_type::FALSE) return logic_type::UNKNOWN;
187  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
188  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
189  if(b == logic_type::TRUE) return logic_type::TRUE;
190  }
191 
192  if (a == logic_type::INCONSISTENT) {
193  if(b == logic_type::FALSE) return logic_type::INCONSISTENT;
194  if(b == logic_type::UNKNOWN) return logic_type::INCONSISTENT;
195  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
196  if(b == logic_type::TRUE) return logic_type::TRUE;
197  }
198 
199  if (a == logic_type::TRUE)
200  return a;
201  }
202 
210  if (a == logic_type::TRUE) {
211  return b;
212  }
213 
214  if (a == logic_type::INCONSISTENT) {
215  if(b == logic_type::FALSE) return logic_type::FALSE;
216  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
217  if(b == logic_type::INCONSISTENT) return logic_type::INCONSISTENT;
218  if(b == logic_type::TRUE) return logic_type::INCONSISTENT;
219  }
220 
221  if (a == logic_type::UNKNOWN) {
222  if(b == logic_type::FALSE) return logic_type::FALSE;
223  if(b == logic_type::UNKNOWN) return logic_type::UNKNOWN;
224  if(b == logic_type::INCONSISTENT) return logic_type::UNKNOWN;
225  if(b == logic_type::TRUE) return logic_type::UNKNOWN;
226  }
227 
228  if (a == logic_type::FALSE)
229  return a;
230  }
231 
238  switch (t) {
239  case Inter4ql::logic_type::FALSE:
240  return std::string("false");
241  case Inter4ql::logic_type::TRUE:
242  return std::string("true");
243  case Inter4ql::logic_type::UNKNOWN:
244  return std::string("unknown");
245  case Inter4ql::logic_type::INCONSISTENT:
246  return std::string("inconsistent");
247  default:
248  return "invalid";
249  }
250  }
251 
258  static Inter4ql::logic_type::type create(bool _t, bool _f) {
259  if (_t && _f)
260  return logic_type::INCONSISTENT;
261  if (!_t && _f)
262  return logic_type::FALSE;
263  if (_t && !_f)
264  return logic_type::TRUE;
265  if (!_t && !_f)
266  return logic_type::UNKNOWN;
267  }
268 
274  static bool is_true(logic_type::type i) {
275  if (i == logic_type::TRUE || i == logic_type::INCONSISTENT)
276  return true;
277  return false;
278  }
279 
285  static bool is_false(logic_type::type i) {
286  if (i == logic_type::FALSE || i == logic_type::INCONSISTENT)
287  return true;
288  return false;
289  }
290 
298  {
299  if (a == b)
300  return false;
301  if (a == logic_type::INCONSISTENT)
302  return true;
303  if (b == logic_type::UNKNOWN)
304  return true;
305  return false;
306 
307  }
308  private:
309 
310  };
311 }
312 
313 #endif /* __LOGIC_H__ */
314 
static bool is_more_knowledge(logic_type::type a, logic_type::type b)
checks if first logic value contains more informations than the second
Definition: Logic.h:297
Static class for handling four-valued logic operations.
Definition: Logic.h:13
static Inter4ql::logic_type::type create(bool _t, bool _f)
craetes four-valued logic value from two booleans
Definition: Logic.h:258
type
Enumeration type for four-valued logic.
Definition: Types.h:45
static bool is_true(logic_type::type i)
checks if input four-valued logic value is true
Definition: Logic.h:274
static logic_type::type TUP(logic_type::type a, logic_type::type b)
returns upper bound on truth ordering
Definition: Logic.h:158
static logic_type::type OR(logic_type::type a, logic_type::type b)
or logic method - in standard logic terms
Definition: Logic.h:41
static logic_type::type OR_RESULT(logic_type::type a, logic_type::type b)
or method - when you have type a in model and put type b...
Definition: Logic.h:21
static bool is_false(logic_type::type i)
checks if input four-valued logic value is false
Definition: Logic.h:285
Definition: Application.cc:37
static std::string get_logic_name(Inter4ql::logic_type::type t)
converts logic value to string
Definition: Logic.h:237
static logic_type::type AND(logic_type::type a, logic_type::type b)
and logic method
Definition: Logic.h:74
static logic_type::type IMPLICATION(logic_type::type a, logic_type::type b)
implication logic method
Definition: Logic.h:107
static logic_type::type NOT(logic_type::type a)
negates logic value
Definition: Logic.h:141
static logic_type::type MIN(logic_type::type a, logic_type::type b)
returns MIN logic value wrt to f<u<i<t order
Definition: Logic.h:209
static logic_type::type MAX(logic_type::type a, logic_type::type b)
returns MAX logic value wrt to f<u<i<t order
Definition: Logic.h:180