Introduction
The simple boolean or Aristotle logic is well-known and widely used in Western World. The development of Information Technologies came to realization that boolean logic is not a sufficient tool for some tasks. Thus it led to tri-boolean logic. The sample of realization of this could be found in boost library.
The Essence
If we take a closer look at the case, it will be found that the tri-boolean logic operates with three conditions: true, false, and something else. Being more precise, this something else is neither true nor false. Following the logic induction, it is clear the tri-boolean logic is incomplete case and it needs one more condition: and true and false.
I am not inventing anything. Four boolean logic is a common case for Asian Buddhism, though it seems something outstanding for Western World.
There is an old Zen puzzle that breaks binary boolean Aristotle logic apart, this is a question of half-full or half-empty glass of water. It is not possible for binary logic to provide an answer on this, as to four boolean logic, it is a simplicity itself.
Here are the four conditions of four boolean logic:
- Pure TRUE
- Pure FALSE
- Neither TRUE nor FALSE
- And TRUE and FALSE
Saying condition, I do not mean state. States could be infinite in number. These four conditions make the boolean logic case complete. It is nothing to add nor to remove.
A Sample
four_boolean.cpp
#include <stdint.h>
#include <inttypes.h>
#include <iostream>
uint8_t send_data(
void* data , uint32_t len );
namespace four_boolean
{
struct resolver
{
resolver (const uint8_t n) : _n(n) {}
bool is_true() const { return _n & 0x01; } bool is_false() const { return _n & 0xFE ? 1 : 0; } uint8_t err_code() const { return _n >> 1; }
uint8_t _n;
};
typedef enum BOOL_tag {
TRUE = 0x01 , FALSE = 0x02 , TRUE_AND_FALSE = TRUE | FALSE , NTRUE_NFALSE = TRUE & FALSE } BOOL;
template <class R> BOOL booler(const R& r) {
return static_cast<BOOL>((r.is_false() << 1) | r.is_true());
}
}
uint8_t send_data_test(
uint8_t retv , void* data , uint32_t len )
{
return retv;
}
void print_four_boolean(const uint8_t retv)
{
four_boolean::resolver r(retv);
switch (four_boolean::booler(r)) {
case four_boolean::TRUE:
std::cout
<< "Pure True;"
<< " data were sent - no errors;"
<< " Err Code: " << (int)r.err_code() << std::endl;
break;
case four_boolean::FALSE:
std::cout
<< "Pure FALSE;"
<< " data were not sent due to:"
<< " Err code: " << (int)r.err_code() << std::endl;
break;
case four_boolean::TRUE_AND_FALSE:
std::cout
<< "And True and False;"
<< " data were sent, but there were some errors:"
<< " Err Code: " << (int)r.err_code() << std::endl;
break;
case four_boolean::NTRUE_NFALSE:
std::cout
<< "Neither True Nor False;"
<< " something unpredictable happened."
<< " it is not possible to make a statement on this;"
<< " Err Code: " << (int)r.err_code() << std::endl;
break;
}
}
int main()
{
uint8_t retv = 23;
std::cout << retv;
print_four_boolean(send_data_test(1, 0, 0));
print_four_boolean(send_data_test(34, 0, 0));
print_four_boolean(send_data_test(99, 0, 0));
print_four_boolean(send_data_test(0, 0, 0));
return 0;
}
The Output
$ g++ ./four-boolean.cpp -o ./four-boolean
$ ./four-boolean
Pure True; data were sent - no errors; Err Code: 0
Pure FALSE; data were not sent due to: Err code: 17
And True and False; data were sent, but there were some errors: Err Code: 49
Neither True Nor False; something unpredictable happened.
It is not possible to make a statement on this; Err Code: 0