ternary

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 4 Imported by: 7

README

Ternary

Three-valued logic based on Kleene's strong logic of indeterminacy.

Build Status GoDoc

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 |
  +----+---+---+---+---+

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

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

const (
	FALSE Value = iota - 1
	UNKNOWN
	TRUE
)

func All

func All(values []Value) Value

All returns the result of logical conjunction on all values.

func And

func And(a Value, b Value) Value

And returns the result of logical conjunction for two values.

func Any

func Any(values []Value) Value

Any returns the result of logical disjunction on all values.

func ConvertFromBool

func ConvertFromBool(b bool) Value

ConvertFromBool converts a boolean to a ternary value. Returns FALSE if the boolean is false, returns TRUE if it is true.

func ConvertFromInt64

func ConvertFromInt64(i int64) (Value, error)

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

func ConvertFromString(s string) (Value, error)

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.

func Equal

func Equal(a Value, b Value) Value

Equal checks if two values are the same value, not logical equality.

func Eqv

func Eqv(a Value, b Value) Value

Eqv returns the result of logical biconditional for two values.

func Imp

func Imp(a Value, b Value) Value

Imp returns the result of logical implication that is represented as "a implies b".

func Not

func Not(a Value) Value

Not returns the result of logical negation for a value.

func Or

func Or(a Value, b Value) Value

Or returns the result of logical disjunction for two values.

func (Value) Int

func (value Value) Int() int64

Int returns integer representation of the value.

func (Value) ParseBool

func (value Value) ParseBool() bool

ParseBool returns true if the value is TRUE, otherwise returns false.

func (Value) String

func (value Value) String() string

String returns string representation of the value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL