-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
153 lines (153 loc) · 5.25 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Package trit implements three-valued logic operations with False,
// Unknown, and True states.
//
// # Overview
//
// Trit (short for "trinary digit") is an information unit that can take three
// states: False (-1), Unknown (0), and True (1). It serves as the fundamental
// unit of trinary/ternary logic systems, with applications in:
// - Database systems (SQL NULL handling)
// - Logic circuits and digital design
// - Decision systems with uncertainty
// - Artificial intelligence and expert systems
// - Configuration management
//
// Key Features
// - Basic type conversion (from/to bool, int, float)
// - Fundamental unary operations (NOT, MA, LA, IA)
// - Binary logic operations (AND, OR, XOR, etc.)
// - Extended operations (IMP, EQ, MIN, MAX)
// - Thread-safe parallel operations for slices
// - Full set of comparison and testing methods
//
// # Quick Start
//
// Basic usage example:
//
// t1 := trit.True
// t2 := trit.Unknown
// result := t1.And(t2) // Unknown
// isTrue := result.IsTrue() // false
//
// # Type System
//
// The package implements type Trit as int8 with three main states:
// - False: Any negative value (-1 and below)
// - Unknown: Zero (0)
// - True: Any positive value (1 and above)
//
// # Truth Tables
//
// The package implements the following truth tables for three-valued logic:
//
// 1. Unary Operations:
//
// - NA (Not): Logical negation
//
// - MA (Modus Ponens Absorption)
//
// - LA (Law of Absorption)
//
// - IA (Implication Absorption)
//
// A | NA A | MA A | LA A | IA
// ----+---- ----+---- ----+---- ----+----
// F | T F | F F | F F | F
// U | U U | T U | F U | T
// T | F T | T T | T T | F
//
// 2. Basic Binary Operations:
//
// - AND: Logical conjunction
//
// - OR: Logical disjunction
//
// - XOR: Exclusive OR
//
// A | B | AND A | B | OR A | B | XOR
// ---+---+------ ---+---+------ ---+---+------
// F | F | F F | F | F F | F | F
// F | U | F F | U | U F | U | U
// F | T | F F | T | T F | T | T
// U | F | F U | F | U U | F | U
// U | U | U U | U | U U | U | U
// U | T | U U | T | T U | T | U
// T | F | F T | F | T T | F | T
// T | U | U T | U | T T | U | U
// T | T | T T | T | T T | T | F
//
// 3. Negative Binary Operations:
//
// - NAND: Logical NAND (NOT AND)
//
// - NOR: Logical NOR (NOT OR)
//
// - NXOR: Logical XNOR (NOT XOR)
//
// A | B | NAND A | B | NOR A | B | NXOR
// ---+---+------ ---+---+------ ---+---+------
// F | F | T F | F | T F | F | T
// F | U | T F | U | U F | U | U
// F | T | T F | T | F F | T | F
// U | F | T U | F | U U | F | U
// U | U | U U | U | U U | U | U
// U | T | U U | T | F U | T | U
// T | F | T T | F | F T | F | F
// T | U | U T | U | F T | U | U
// T | T | F T | T | F T | T | T
//
// 4. Extended Operations:
//
// - IMP: Implication (Lukasiewicz Logic)
//
// - EQ: Equivalence (If and only if)
//
// - MIN: Minimum value
//
// - NIMP: Inverse implication
//
// - NEQ: Non-equivalence
//
// - MAX: Maximum value
//
// A | B | IMP A | B | EQ A | B | MIN
// ---+---+------ ---+---+------ ---+---+------
// F | F | T F | F | T F | F | F
// F | U | T F | U | U F | U | F
// F | T | T F | T | F F | T | F
// U | F | U U | F | U U | F | F
// U | U | T U | U | U U | U | U
// U | T | T U | T | U U | T | U
// T | F | F T | F | F T | F | F
// T | U | U T | U | U T | U | U
// T | T | T T | T | T T | T | T
//
// A | B | NIMP A | B | NEQ A | B | MAX
// ---+---+------ ---+---+------ ---+---+------
// F | F | F F | F | F F | F | F
// F | U | F F | U | U F | U | U
// F | T | F F | T | T F | T | T
// U | F | U U | F | U U | F | U
// U | U | F U | U | U U | U | U
// U | T | F U | T | U U | T | T
// T | F | T T | F | T T | F | T
// T | U | U T | U | U T | U | T
// T | T | F T | T | F T | T | T
//
// # Thread Safety
//
// All operations in this package are thread-safe. The parallel operations
// (All, Any, Known) use goroutines for processing large slices and include
// proper synchronization mechanisms.
//
// # Performance Considerations
//
// The package optimizes performance by:
// - Using int8 as the underlying type
// - Implementing efficient parallel processing for slice operations
// - Providing direct value access methods
// - Minimizing memory allocations
//
// For more examples and detailed API documentation, see the individual method
// documentation and the package examples.
package trit