Documentation ¶
Overview ¶
Package ternary is a Go library to calculate three-valued logic.
This package is based on Kleene's strong logic of indeterminacy. Ternary has three truth values, TRUE, FALSE and UNKNOWN.
Numeric representation of truth values
FALSE: -1 UNKNOWN: 0 TRUE: 1
Truth tables
NOT(A) - Logical negation +---+----+ | A | ¬A | |---+----| | F | T | | U | U | | T | F | +---+----+ AND(A, B) - Logical conjunction. Minimum value of (A, B) +--------+-----------| | | B | | A ∧ B |---+---+---| | | F | U | T | |----+---+---+---+---| | | F | F | F | F | | A | U | F | U | U | | | T | F | U | T | +----+---+---+---+---+ OR(A, B) - Logical disjunction. Maximum value of (A, B) +--------+-----------+ | | B | | A ∨ B |---+---+---| | | F | U | T | |----+---+---+---+---| | | F | F | U | T | | A | U | U | U | T | | | T | T | T | T | +----+---+---+---+---+ IMP(A, B) - Logical implication. OR(NOT(A), B) +--------+-----------+ | | B | | A → B |---+---+---| | | F | U | T | |----+---+---+---+---| | | F | T | T | T | | A | U | U | U | T | | | T | F | U | T | +----+---+---+---+---+ EQV(A, B) - Logical biconditional. OR(AND(A, B), AND(NOT(A), NOT(B))) +--------+-----------+ | | B | | A ↔ B |---+---+---| | | F | U | T | |----+---+---+---+---| | | F | T | U | F | | A | U | U | U | U | | | T | F | U | T | +----+---+---+---+---+
Index ¶
- type Value
- func All(values []Value) Value
- func And(a Value, b Value) Value
- func Any(values []Value) Value
- func ConvertFromBool(b bool) Value
- func ConvertFromInt64(i int64) (Value, error)
- func ConvertFromString(s string) (Value, error)
- func Equal(a Value, b Value) Value
- func Eqv(a Value, b Value) Value
- func Imp(a Value, b Value) Value
- func Not(a Value) Value
- func Or(a Value, b Value) Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value int8
Value represents a truth value
func ConvertFromBool ¶
ConvertFromBool converts a boolean to a ternary value. Returns FALSE if the boolean is false, returns TRUE if it is true.
func ConvertFromInt64 ¶
ConvertFromInt64 converts an integer to a ternary value. Returns FALSE if the integer is -1, returns UNKNOWN if it is 0, and returns TRUE if it is 1. Otherwise, returns an error.
func ConvertFromString ¶
ConvertFromString converts a string to a ternary value. If the string is any of "false", "FALSE" and "-1", then it is converted to FALSE. If the string is any of "unknown", "UNKNOWN" and "0", then it is converted to UNKNOWN. If the string is any of "true", "TRUE" and "1", then it is converted to TRUE. Otherwise, returns an error.