BitMagic-C++
three-valued logic

Functions for three-valued logic (Kleene) https://en.wikipedia.org/wiki/Three-valued_logic. More...

Collaboration diagram for three-valued logic:

## Functions

template<class BV >
void bm::init_kleene (BV &bv_value, const BV &bv_null)
Initialized the value bit-vector so that it always returns 0 (false) for the unknown. More...

template<class BV >
int bm::get_value_kleene (const BV &bv_value, const BV &bv_null, typename BV::size_type idx) BMNOEXCEPT
Return Kleene logic value based on value and known vectors. More...

template<class BV >
void bm::set_value_kleene (BV &bv_value, BV &bv_null, typename BV::size_type idx, int val)
Set Kleene logic value based on value and known vectors. More...

template<class BV >
void bm::invert_kleene (BV &bv_value, const BV &bv_null)
Kleene NEG operation. More...

template<class BV >
void bm::or_kleene (BV &bv_value1, BV &bv_null1, const BV &bv_value2, const BV &bv_null2)
Kleene OR(vect1, vect2) (vect1 |= vect2) 1 OR Unk = 1 (known) More...

template<class BV >
void bm::or_kleene (BV &bv_value_target, BV &bv_null_target, const BV &bv_value1, const BV &bv_null1, const BV &bv_value2, const BV &bv_null2)
3-way Kleene OR: target := OR(vect1, vect2) (target := vect1 | vect2) 1 OR Unk = 1 (known) More...

template<class BV >
void bm::and_kleene (BV &bv_value1, BV &bv_null1, const BV &bv_value2, const BV &bv_null2)
Kleene AND(vect1, vect2) (vect1 &= vect2) 0 AND Unk = 0 (known) More...

template<class BV >
void bm::and_kleene (BV &bv_value_target, BV &bv_null_target, const BV &bv_value1, const BV &bv_null1, const BV &bv_value2, const BV &bv_null2)
3-way Kleene target:=AND(vect1, vect2) (target:= vect1 & vect2) 0 AND Unk = 0 (known) More...

int bm::and_values_kleene (int a, int b) BMNOEXCEPT
Reference function for Kleene logic AND (for verification and testing) More...

int bm::or_values_kleene (int a, int b) BMNOEXCEPT
Reference function for Kleene logic OR (for verification and testing) More...

## Detailed Description

Functions for three-valued logic (Kleene) https://en.wikipedia.org/wiki/Three-valued_logic.

## ◆ and_kleene() [1/2]

template<class BV >
 void bm::and_kleene ( BV & bv_value1, BV & bv_null1, const BV & bv_value2, const BV & bv_null2 )

Kleene AND(vect1, vect2) (vect1 &= vect2) 0 AND Unk = 0 (known)

Parameters
 bv_value1 - [in, out] values bit-vector bv_null1 - [in, out] not NULL (known) bit-vector bv_value2 - [in] values bit-vector bv_null2 - [in] not NULL (known) bit-vector
Examples
bv3vlogic.cpp.

Definition at line 213 of file bm3vl.h.

Referenced by Set3VL_AndDemo().

## ◆ and_kleene() [2/2]

template<class BV >
 void bm::and_kleene ( BV & bv_value_target, BV & bv_null_target, const BV & bv_value1, const BV & bv_null1, const BV & bv_value2, const BV & bv_null2 )

3-way Kleene target:=AND(vect1, vect2) (target:= vect1 & vect2) 0 AND Unk = 0 (known)

Parameters
 bv_value_target - [out] values bit-vector bv_null_target - [out] not NULL (known) bit-vector bv_value1 - [in] values bit-vector bv_null1 - [in] not NULL (known) bit-vector bv_value2 - [in] values bit-vector bv_null2 - [in] not NULL (known) bit-vector

Definition at line 245 of file bm3vl.h.

## ◆ and_values_kleene()

 int bm::and_values_kleene ( int a, int b )
inline

Reference function for Kleene logic AND (for verification and testing)

Definition at line 271 of file bm3vl.h.

References BM_ASSERT.

## ◆ get_value_kleene()

template<class BV >
 int bm::get_value_kleene ( const BV & bv_value, const BV & bv_null, typename BV::size_type idx )

Return Kleene logic value based on value and known vectors.

Parameters
 bv_value - [in] values bit-vector bv_null - [in] knowns bit-vector idx - [in] index of value to extract and return
Returns
(−1: false; 0: unknown; +1: true)
Examples
bv3vlogic.cpp.

Definition at line 70 of file bm3vl.h.

Referenced by Set3VL_ValueDemo().

## ◆ init_kleene()

template<class BV >
 void bm::init_kleene ( BV & bv_value, const BV & bv_null )

Initialized the value bit-vector so that it always returns 0 (false) for the unknown.

3-value logics in BitMagic is built on two bit-vectors: value-bit-vector and NULL bit-vector. Value vector contains '1s' for the true known elements. bm::init_3vl makes sure this is true by running bv_value = bv_value AND bv_null logical operation. NULL bit-vector represents NOT NULL (known) values as 1s

Parameters
 bv_value - [in, out] values bit-vector bv_null - [in] not NULL (known) bit-vector
Examples
bv3vlogic.cpp.

Definition at line 54 of file bm3vl.h.

Referenced by Set3VL_ValueDemo2().

## ◆ invert_kleene()

template<class BV >
 void bm::invert_kleene ( BV & bv_value, const BV & bv_null )

Kleene NEG operation.

True becomes false and vice verse, but unknowns remain unknown false if we look directly into bv_value vector. This oprtaion does NOT produce unknown true values.

Parameters
 bv_value - [in, out] values bit-vector bv_null - [in] not NULL (known) bit-vector
Examples
bv3vlogic.cpp.

Definition at line 135 of file bm3vl.h.

Referenced by Set3VL_InvertDemo().

## ◆ or_kleene() [1/2]

template<class BV >
 void bm::or_kleene ( BV & bv_value1, BV & bv_null1, const BV & bv_value2, const BV & bv_null2 )

Kleene OR(vect1, vect2) (vect1 |= vect2) 1 OR Unk = 1 (known)

Parameters
 bv_value1 - [in, out] values bit-vector bv_null1 - [in, out] not NULL (known) bit-vector bv_value2 - [in] values bit-vector bv_null2 - [in] not NULL (known) bit-vector
Examples
bv3vlogic.cpp.

Definition at line 151 of file bm3vl.h.

Referenced by Set3VL_ORDemo().

## ◆ or_kleene() [2/2]

template<class BV >
 void bm::or_kleene ( BV & bv_value_target, BV & bv_null_target, const BV & bv_value1, const BV & bv_null1, const BV & bv_value2, const BV & bv_null2 )

3-way Kleene OR: target := OR(vect1, vect2) (target := vect1 | vect2) 1 OR Unk = 1 (known)

Parameters
 bv_value_target - [out] target values bit-vector bv_null_target - [out] target not NULL (known) bit-vector bv_value1 - [in] values bit-vector bv_null1 - [in] not NULL (known) bit-vector bv_value2 - [in] values bit-vector bv_null2 - [in] not NULL (known) bit-vector

Definition at line 181 of file bm3vl.h.

## ◆ or_values_kleene()

 int bm::or_values_kleene ( int a, int b )
inline

Reference function for Kleene logic OR (for verification and testing)

Definition at line 311 of file bm3vl.h.

References BM_ASSERT.

## ◆ set_value_kleene()

template<class BV >
 void bm::set_value_kleene ( BV & bv_value, BV & bv_null, typename BV::size_type idx, int val )

Set Kleene logic value based on value and known vectors.

Parameters
 bv_value - [out] values bit-vector bv_null - [out] knowns bit-vector idx - [in] index of value to extract and return val - [in] value which can be: (−1: false; 0: unknown; +1: true)
Examples
bv3vlogic.cpp.

Definition at line 96 of file bm3vl.h.

References BM_ASSERT.

Referenced by GenerateDemoVector(), Set3VL_AndDemo(), Set3VL_ORDemo(), and Set3VL_ValueDemo().