Documentation
¶
Index ¶
Constants ¶
const ( B0 = Bit(0) B1 = Bit(1) )
Shortcuts for bits. Remember to compare a Bit with a Bit, not with an int!
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bit ¶
type Bit int // bit, as integer
A new Gate is defined by a truth table, or by a choicetable
type Bits ¶
type Bits []Bit // input bits, or output bits
A new Gate is defined by a truth table, or by a choicetable
func Reverse ¶
func Reverse(tt *TruthTable, output Bit, vf ValidatorFunc) (foundInput *Bits, iterations uint, err error)
Given a truth table and an output bit, reverse the output and find the input. Also needs a ValidatorFunc to return true when the correct input has been found. Returns the found input, number of iterations that were required and an error if not found
func StringToBits ¶
StringToBits converts a space-separated string of "0"s and "1"s to a pointer to a slice of bits.Bit. Returns an error if an invalid string is given.
type Choices ¶
type Choices []Bits
Multiple possible outputs, with equal probability
func NewChoices ¶
Takes a string like this: "0 0 | 0 1 | 1 0 | 1 1" and returns the four elements (separated by "|") as *Choices (slice of Bits)
func StringToChoices ¶
Takes a string like this: "0 0 | 0 1 | 1 0 | 1 1" and returns the four elements (separated by "|") as Choices (slice of Bits)
type Gater ¶
type Gater interface {
Process(interface{}) interface{}
}
A gate must have a Process function, that can take Input or Inputs, and return Output or Outputs
type ManyToManyGate ¶
A ManyToManyGate can have several inputs and outputs
func (*ManyToManyGate) Process ¶
func (mg *ManyToManyGate) Process(inputOrInputs interface{}) (outputOrOutputs interface{})
Multi can act as a gate (Gater) many to many
type MultiProbGate ¶
A probgate with many inputs and several possible outputs Example prob table: {"0 1 1 0 1 -> 1 1 | 0 0"}, would return Choices{Outputs{1, 1}, Outputs{0, 0}} if given 0
func (*MultiProbGate) Process ¶
func (cg *MultiProbGate) Process(inputOrInputs interface{}) (outputOrOutputs interface{})
Multi Choice Gate can act as a gate (Gater) many bits to many possible choices
type OneToManyGate ¶
A logic gate with multiple inputs and one output
func NewOneToManyGate ¶
func NewOneToManyGate(tt *TruthTable) *OneToManyGate
Create a new logic gate, like "and" or "xor", with inputs and one output
func (*OneToManyGate) Process ¶
func (lg *OneToManyGate) Process(inputOrInputs interface{}) (outputOrOutputs interface{})
OneToManyGate can act as a gate (Gater) many to one
type OneToOneGate ¶
A logic gate (like "not")
func (*OneToOneGate) Process ¶
func (ug *OneToOneGate) Process(inputOrInputs interface{}) (outputOrOutputs interface{})
OneToOneGate can act as a gate (Gater) one to one
type ProbGate ¶
A simple probgate with one input and several possible outputs Example prob table: {"0 -> 1 1 | 0 0"}, would return Choices{Outputs{1, 1}, Outputs{0, 0}} if given 0
func NewProbGate ¶
Create a new probability gate, a ProbGate, where one input can give many alternative outputs
type ProbTable ¶
type ProbTable []string
type TruthTable ¶
type TruthTable []string
func (*TruthTable) Complete ¶
func (tt *TruthTable) Complete() bool
Check if a truth table is complete If tables are assumed to not contain duplicates, one could just count the rows too
func (*TruthTable) Gate ¶
func (tt *TruthTable) Gate() OneToManyGate
Take truth table, return a Gate
func (*TruthTable) Invert ¶
func (tt *TruthTable) Invert() *ProbTable
Make it possible to run a truth table in reverse, by returning a table with probabilities
func (*TruthTable) Process ¶
func (tt *TruthTable) Process(inputs Bits) Bit
TruthTable can act as a gate (Gater), many to one
func (*TruthTable) String ¶
func (tt *TruthTable) String() string