## Base-k computations in Lisp

A base-k number can be written as a list

(an an-1a1 a0)

where 0 ≤ aq < k in the standard (unbalanced) form. In the balanced form, the values of aq are in the following range:

−(k−1)/2 ≤ aq ≤ (k−1)/2 if k is odd;
−(k−2)/2 ≤ aq ≤ (k)/2 if k is even;

q = 0, 1, …, n.

Examples:

For binary numbers (k = 2), aq = 0, 1.
For ternary numbers (k = 3), aq = 0, 1, 2.
For quaternary numbers (k = 4), aq = 0, 1, 2, 3.
For quinary numbers (k = 5), aq = 0, 1, 2, 3, 4.
Etc.

Balanced form examples:

For binary numbers (k = 2), aq = 0, 1.
For ternary numbers (k = 3), aq = −1, 0, 1.
For quaternary numbers (k = 4), aq = −1, 0, 1, 2.
For quinary numbers (k = 5), aq = −2, −1, 0, 1, 2.
Etc.

Using lists eliminates the need to invent additional symbols for number systems with the base > 10 (or > 19 for a balanced form).

For example, 210 is (10 10) in vigesimal.

The decimal number corresponding to the list (an an-1a1 a0) is

N = ankn + an-1kn-1 + … + a1k1 + a0k0

The range of numbers expressed as a list of this length (n+1), in the unbalanced form, is

[0, kn+1−1]

In the balanced form, if k is odd, the range is:

[−(kn+1−1)/2, (kn+1−1)/2]

and, k is even, then

[−(k−2)(kn+1−1)/(2(k−1)), k(kn+1−1)/(2(k−1))]

Lisp functions for calculating the range:

```
(defun min-num (lst-length k &key (balanced t))
(if balanced
(if (oddp k)
(/ (- (expt k lst-length) 1) -2)
(/ (* (- k 2) (- (expt k lst-length) 1))
(* -2 (- k 1))))
0))

(defun max-num (lst-length k &key (balanced t))
(if balanced
(if (oddp k)
(/ (- (expt k lst-length) 1) 2)
(/ (* k (- (expt k lst-length) 1))
(* 2 (- k 1))))
(- (expt k lst-length) 1)))
```

A base-k list can be converted to decimal with the following function:

```
(defun base-k-to-decimal (lst k)
(reduce (lambda (x y) (+ (* x k) y)) lst))
```

Decimal to base-k conversion can be done by using integer division:

```
(defun decimal-to-base-k (num k)
(if (= num 0)
(list 0)
(reverse
(loop for n = num then (truncate (/ n k))
until (and (= (truncate (/ n k)) 0)
(= (rem n k) 0))
collect (rem n k)))))
```

A base-k number can be decoded into a real number r in the range [rmin, rmax] by first decoding it into the decimal integer i and then applying the formula

r = rmin + (iimin) (rmaxrmin)/(imaximin),

where imax and imin are the maximum and the minimum integer values represented by a base-k list of a certain fixed length l.

Here’s a function for decoding a base-k number to real:

```
(defun base-k-to-real (lst k r-min r-max &key (balanced t))
(let ((i-min (min-num (length lst) k :balanced balanced))
(i-max (max-num (length lst) k :balanced balanced)))
(* 1.0 (+ r-min
(/ (* (- (base-k-to-decimal lst k) i-min)
(- r-max r-min))
(- i-max i-min))))))
```

Standard versus balanced form, odd k:

 unbalanced balanced (0) (0) (1) (1) … ((k−3)/2) ((k−3)/2) ((k−1)/2) ((k−1)/2) ((k+1)/2) (1 −(k−1)/2) ((k+3)/2) (1 −(k−3)/2) … (k−2) (1 −2) (k−1) (1 −1)

Standard versus balanced form, even k:

 unbalanced balanced (0) (0) (1) (1) … ((k−2)/2) ((k−2)/2) (k/2) (k/2) ((k+2)/2) (1 −(k−2)/2) ((k+4)/2) (1 −(k−4)/2) … (k−2) (1 −2) (k−1) (1 −1)

Using these tables, converting base-k to balanced base-k can be done as follows:

```
(defun unbalanced-to-balanced (lst k)
(loop with carry = 0
with ai = 0
for i in (reverse lst) do
(if (> (+ i carry) (/ (- k (mod k 2)) 2))
(setf ai (- (+ i carry) k)
carry 1)
(setf ai (+ i carry)
carry 0))
collect ai into balanced
finally (return
(if (/= carry 0)
(cons carry (reverse balanced))
(reverse balanced)))))
```

Unary logic gates

Unary logic gates transform a single input number to an output number.

There are kk unary logic gates in base-k.

For example, there are 22 = 4 unary logic gates in Boolean algebra:

1. Identity: 1 → 1, 0 → 0
2. Inversion: 1 → 0, 0 → 1
3. Shift up: 1 → 1, 0 → 1
4. Shift down: 1 → 0, 0 → 0

In ternary algebra, there are 33 = 27 unary logic gates:

 Input -1 0 1 Output Minus one -1 -1 -1 Shift right with minus one -1 -1 0 Zero to minus one -1 -1 1 Minus modulus -1 0 -1 (-1)-polarizer -1 0 0 Identity -1 0 1 Through one to minus one -1 1 -1 Toggle one -1 1 0 Zero to one -1 1 1 Gimble right 0 -1 -1 (-1)-inverter 0 -1 0 Toggle minus one 0 -1 1 Double-gimble right 0 0 -1 Zero 0 0 0 (1)-polarizer 0 0 1 Rotate left 0 1 -1 (1)-inverter 0 1 0 Shift left with one 0 1 1 Gyre left 1 -1 -1 Rotate right 1 -1 0 Through minus one to one 1 -1 1 Change polarization 1 0 -1 Double-gimble left 1 0 0 Modulus 1 0 1 Gyre right 1 1 -1 Gimble left 1 1 0 One 1 1 1

Binary logic gates

Binary logic gates transform two input numbers to a single output number.

Because of the symmetry (permutations of the inputs should not change the output), there are k(k(k+1)/2) binary logic gates in base-k algebra.

For example, there are 2(2(2+1)/2) = 8 binary logic gates in Boolean algebra:

 Input 1 0 1 1 Input 2 0 0 1 Output Zero 0 0 0 And 0 0 1 Xor 0 1 0 Or 0 1 1 Nor 1 0 0 Xnor 1 0 1 Nand 1 1 0 One 1 1 1

In ternary algebra, there are 3(3(3+1)/2) = 36 = 729 binary logic gates:

 Input 1 -1 0 1 0 1 1 Input 2 -1 -1 -1 0 0 1 Output Minus one -1 -1 -1 -1 -1 -1 Minus (1,1)-nand -1 -1 -1 -1 -1 0 … -1 -1 -1 -1 -1 1 Minus (0,1)-xnor -1 -1 -1 -1 0 -1 Minus (0,1;1,1)-nor -1 -1 -1 -1 0 0 … -1 -1 -1 -1 0 1 … -1 -1 -1 -1 1 -1 … -1 -1 -1 -1 1 0 … -1 -1 -1 -1 1 1 Minus (0,0)-nand -1 -1 -1 0 -1 -1 Minus (0,0;1,1)-nor -1 -1 -1 0 -1 0 … -1 -1 -1 0 -1 1 Minus (0,0;0,1)-nor -1 -1 -1 0 0 -1 Minus (-1)-or -1 -1 -1 0 0 0 Minimum -1 -1 -1 0 0 1 … -1 -1 -1 0 1 -1 … -1 -1 -1 0 1 0 … -1 -1 -1 0 1 1 … -1 -1 -1 1 -1 -1 … -1 -1 -1 1 -1 0 … -1 -1 -1 1 -1 1 … -1 -1 -1 1 0 -1 … -1 -1 -1 1 0 0 … -1 -1 -1 1 0 1 … -1 -1 -1 1 1 -1 … -1 -1 -1 1 1 0 … -1 -1 -1 1 1 1 Minus (-1,1)-xnor -1 -1 0 -1 -1 -1 Minus (-1,1;1,1)-nor -1 -1 0 -1 -1 0 … -1 -1 0 -1 -1 1 Minus (-1,1;0,1)-nor -1 -1 0 -1 0 -1 Minus (1)-nor -1 -1 0 -1 0 0 … -1 -1 0 -1 0 1 … -1 -1 0 -1 1 -1 … -1 -1 0 -1 1 0 … -1 -1 0 -1 1 1 … -1 -1 0 0 -1 -1 … -1 -1 0 0 -1 0 … -1 -1 0 0 -1 1 … -1 -1 0 0 0 -1 … -1 -1 0 0 0 0 … -1 -1 0 0 0 1 … -1 -1 0 0 1 -1 … -1 -1 0 0 1 0 … -1 -1 0 0 1 1 … -1 -1 0 1 -1 -1 … -1 -1 0 1 -1 0 … -1 -1 0 1 -1 1 … -1 -1 0 1 0 -1 … -1 -1 0 1 0 0 … -1 -1 0 1 0 1 … -1 -1 0 1 1 -1 … -1 -1 0 1 1 0 … -1 -1 0 1 1 1 … -1 -1 1 -1 -1 -1 … -1 -1 1 -1 -1 0 … -1 -1 1 -1 -1 1 … -1 -1 1 -1 0 -1 … -1 -1 1 -1 0 0 … -1 -1 1 -1 0 1 … -1 -1 1 -1 1 -1 … -1 -1 1 -1 1 0 … -1 -1 1 -1 1 1 … -1 -1 1 0 -1 -1 … -1 -1 1 0 -1 0 … -1 -1 1 0 -1 1 … -1 -1 1 0 0 -1 … -1 -1 1 0 0 0 … -1 -1 1 0 0 1 … -1 -1 1 0 1 -1 … -1 -1 1 0 1 0 … -1 -1 1 0 1 1 … -1 -1 1 1 -1 -1 … -1 -1 1 1 -1 0 … -1 -1 1 1 -1 1 … -1 -1 1 1 0 -1 … -1 -1 1 1 0 0 … -1 -1 1 1 0 1 … -1 -1 1 1 1 -1 … -1 -1 1 1 1 0 … -1 -1 1 1 1 1 … -1 0 -1 -1 -1 -1 … -1 0 -1 -1 -1 0 … -1 0 -1 -1 -1 1 … -1 0 -1 -1 0 -1 … -1 0 -1 -1 0 0 … -1 0 -1 -1 0 1 … -1 0 -1 -1 1 -1 … -1 0 -1 -1 1 0 … -1 0 -1 -1 1 1 … -1 0 -1 0 -1 -1 … -1 0 -1 0 -1 0 … -1 0 -1 0 -1 1 … -1 0 -1 0 0 -1 … -1 0 -1 0 0 0 … -1 0 -1 0 0 1 … -1 0 -1 0 1 -1 … -1 0 -1 0 1 0 … -1 0 -1 0 1 1 … -1 0 -1 1 -1 -1 … -1 0 -1 1 -1 0 … -1 0 -1 1 -1 1 … -1 0 -1 1 0 -1 … -1 0 -1 1 0 0 … -1 0 -1 1 0 1 … -1 0 -1 1 1 -1 … -1 0 -1 1 1 0 … -1 0 -1 1 1 1 … -1 0 0 -1 -1 -1 … -1 0 0 -1 -1 0 … -1 0 0 -1 -1 1 … -1 0 0 -1 0 -1 … -1 0 0 -1 0 0 … -1 0 0 -1 0 1 … -1 0 0 -1 1 -1 … -1 0 0 -1 1 0 … -1 0 0 -1 1 1 … -1 0 0 0 -1 -1 … -1 0 0 0 -1 0 … -1 0 0 0 -1 1 … -1 0 0 0 0 -1 Minus (-1,-1)-and -1 0 0 0 0 0 … -1 0 0 0 0 1 … -1 0 0 0 1 -1 … -1 0 0 0 1 0 … -1 0 0 0 1 1 … -1 0 0 1 -1 -1 … -1 0 0 1 -1 0 … -1 0 0 1 -1 1 … -1 0 0 1 0 -1 … -1 0 0 1 0 0 … -1 0 0 1 0 1 … -1 0 0 1 1 -1 … -1 0 0 1 1 0 … -1 0 0 1 1 1 … -1 0 1 -1 -1 -1 … -1 0 1 -1 -1 0 … -1 0 1 -1 -1 1 … -1 0 1 -1 0 -1 … -1 0 1 -1 0 0 … -1 0 1 -1 0 1 … -1 0 1 -1 1 -1 … -1 0 1 -1 1 0 … -1 0 1 -1 1 1 … -1 0 1 0 -1 -1 … -1 0 1 0 -1 0 … -1 0 1 0 -1 1 … -1 0 1 0 0 -1 … -1 0 1 0 0 0 … -1 0 1 0 0 1 … -1 0 1 0 1 -1 … -1 0 1 0 1 0 Maximum -1 0 1 0 1 1 … -1 0 1 1 -1 -1 … -1 0 1 1 -1 0 … -1 0 1 1 -1 1 … -1 0 1 1 0 -1 … -1 0 1 1 0 0 … -1 0 1 1 0 1 … -1 0 1 1 1 -1 … -1 0 1 1 1 0 … -1 0 1 1 1 1 … -1 1 -1 -1 -1 -1 … -1 1 -1 -1 -1 0 … -1 1 -1 -1 -1 1 … -1 1 -1 -1 0 -1 … -1 1 -1 -1 0 0 … -1 1 -1 -1 0 1 … -1 1 -1 -1 1 -1 … -1 1 -1 -1 1 0 … -1 1 -1 -1 1 1 … -1 1 -1 0 -1 -1 … -1 1 -1 0 -1 0 … -1 1 -1 0 -1 1 … -1 1 -1 0 0 -1 … -1 1 -1 0 0 0 … -1 1 -1 0 0 1 … -1 1 -1 0 1 -1 … -1 1 -1 0 1 0 … -1 1 -1 0 1 1 … -1 1 -1 1 -1 -1 … -1 1 -1 1 -1 0 … -1 1 -1 1 -1 1 … -1 1 -1 1 0 -1 … -1 1 -1 1 0 0 … -1 1 -1 1 0 1 … -1 1 -1 1 1 -1 … -1 1 -1 1 1 0 … -1 1 -1 1 1 1 … -1 1 0 -1 -1 -1 … -1 1 0 -1 -1 0 … -1 1 0 -1 -1 1 … -1 1 0 -1 0 -1 … -1 1 0 -1 0 0 … -1 1 0 -1 0 1 … -1 1 0 -1 1 -1 … -1 1 0 -1 1 0 … -1 1 0 -1 1 1 … -1 1 0 0 -1 -1 … -1 1 0 0 -1 0 … -1 1 0 0 -1 1 … -1 1 0 0 0 -1 … -1 1 0 0 0 0 … -1 1 0 0 0 1 … -1 1 0 0 1 -1 … -1 1 0 0 1 0 … -1 1 0 0 1 1 … -1 1 0 1 -1 -1 … -1 1 0 1 -1 0 … -1 1 0 1 -1 1 … -1 1 0 1 0 -1 … -1 1 0 1 0 0 … -1 1 0 1 0 1 … -1 1 0 1 1 -1 … -1 1 0 1 1 0 … -1 1 0 1 1 1 … -1 1 1 -1 -1 -1 … -1 1 1 -1 -1 0 … -1 1 1 -1 -1 1 … -1 1 1 -1 0 -1 … -1 1 1 -1 0 0 … -1 1 1 -1 0 1 … -1 1 1 -1 1 -1 … -1 1 1 -1 1 0 … -1 1 1 -1 1 1 … -1 1 1 0 -1 -1 Minus modulus of difference -1 1 1 0 -1 0 … -1 1 1 0 -1 1 … -1 1 1 0 0 -1 … -1 1 1 0 0 0 … -1 1 1 0 0 1 … -1 1 1 0 1 -1 … -1 1 1 0 1 0 … -1 1 1 0 1 1 … -1 1 1 1 -1 -1 … -1 1 1 1 -1 0 … -1 1 1 1 -1 1 … -1 1 1 1 0 -1 … -1 1 1 1 0 0 … -1 1 1 1 0 1 … -1 1 1 1 1 -1 … -1 1 1 1 1 0 … -1 1 1 1 1 1 Minus (-1,-1)-nand 0 -1 -1 -1 -1 -1 Minus (-1,-1;1,1)-nor 0 -1 -1 -1 -1 0 … 0 -1 -1 -1 -1 1 Minus (-1,-1;0,1)-nor 0 -1 -1 -1 0 -1 … 0 -1 -1 -1 0 0 … 0 -1 -1 -1 0 1 … 0 -1 -1 -1 1 -1 … 0 -1 -1 -1 1 0 … 0 -1 -1 -1 1 1 Minus (-1,-1;0,0)-nor 0 -1 -1 0 -1 -1 … 0 -1 -1 0 -1 0 … 0 -1 -1 0 -1 1 … 0 -1 -1 0 0 -1 … 0 -1 -1 0 0 0 … 0 -1 -1 0 0 1 … 0 -1 -1 0 1 -1 … 0 -1 -1 0 1 0 … 0 -1 -1 0 1 1 … 0 -1 -1 1 -1 -1 … 0 -1 -1 1 -1 0 … 0 -1 -1 1 -1 1 … 0 -1 -1 1 0 -1 … 0 -1 -1 1 0 0 … 0 -1 -1 1 0 1 … 0 -1 -1 1 1 -1 … 0 -1 -1 1 1 0 … 0 -1 -1 1 1 1 Minus (-1,-1;-1,1)-nor 0 -1 0 -1 -1 -1 … 0 -1 0 -1 -1 0 … 0 -1 0 -1 -1 1 … 0 -1 0 -1 0 -1 Minus (-1,0;0,0)-or 0 -1 0 -1 0 0 … 0 -1 0 -1 0 1 … 0 -1 0 -1 1 -1 … 0 -1 0 -1 1 0 … 0 -1 0 -1 1 1 … 0 -1 0 0 -1 -1 Minus (-1,0;0,1)-or 0 -1 0 0 -1 0 … 0 -1 0 0 -1 1 Minus (-1,0;1,1)-or 0 -1 0 0 0 -1 Minus (-1,0)-xor 0 -1 0 0 0 0 … 0 -1 0 0 0 1 … 0 -1 0 0 1 -1 … 0 -1 0 0 1 0 … 0 -1 0 0 1 1 … 0 -1 0 1 -1 -1 … 0 -1 0 1 -1 0 … 0 -1 0 1 -1 1 … 0 -1 0 1 0 -1 … 0 -1 0 1 0 0 … 0 -1 0 1 0 1 … 0 -1 0 1 1 -1 … 0 -1 0 1 1 0 … 0 -1 0 1 1 1 … 0 -1 1 -1 -1 -1 … 0 -1 1 -1 -1 0 … 0 -1 1 -1 -1 1 … 0 -1 1 -1 0 -1 … 0 -1 1 -1 0 0 … 0 -1 1 -1 0 1 … 0 -1 1 -1 1 -1 … 0 -1 1 -1 1 0 … 0 -1 1 -1 1 1 … 0 -1 1 0 -1 -1 … 0 -1 1 0 -1 0 … 0 -1 1 0 -1 1 … 0 -1 1 0 0 -1 … 0 -1 1 0 0 0 … 0 -1 1 0 0 1 … 0 -1 1 0 1 -1 … 0 -1 1 0 1 0 … 0 -1 1 0 1 1 … 0 -1 1 1 -1 -1 … 0 -1 1 1 -1 0 … 0 -1 1 1 -1 1 … 0 -1 1 1 0 -1 … 0 -1 1 1 0 0 … 0 -1 1 1 0 1 … 0 -1 1 1 1 -1 … 0 -1 1 1 1 0 … 0 -1 1 1 1 1 Minus (-1,-1;-1,0)-nor 0 0 -1 -1 -1 -1 … 0 0 -1 -1 -1 0 … 0 0 -1 -1 -1 1 … 0 0 -1 -1 0 -1 Minus (-1,1;0,0)-or 0 0 -1 -1 0 0 … 0 0 -1 -1 0 1 … 0 0 -1 -1 1 -1 … 0 0 -1 -1 1 0 … 0 0 -1 -1 1 1 Minus (1)-or 0 0 -1 0 -1 -1 Minus (-1,1;0,1)-or 0 0 -1 0 -1 0 … 0 0 -1 0 -1 1 Minus (-1,1;1,1)-or 0 0 -1 0 0 -1 Minus (-1,1)-xor 0 0 -1 0 0 0 … 0 0 -1 0 0 1 … 0 0 -1 0 1 -1 … 0 0 -1 0 1 0 … 0 0 -1 0 1 1 … 0 0 -1 1 -1 -1 … 0 0 -1 1 -1 0 … 0 0 -1 1 -1 1 … 0 0 -1 1 0 -1 … 0 0 -1 1 0 0 … 0 0 -1 1 0 1 … 0 0 -1 1 1 -1 … 0 0 -1 1 1 0 … 0 0 -1 1 1 1 Minus (-1)-nor 0 0 0 -1 -1 -1 Minus (0,0;0,1)-or 0 0 0 -1 -1 0 … 0 0 0 -1 -1 1 Minus (0,0;1,1)-or 0 0 0 -1 0 -1 Minus (0,0)-and 0 0 0 -1 0 0 … 0 0 0 -1 0 1 … 0 0 0 -1 1 -1 … 0 0 0 -1 1 0 … 0 0 0 -1 1 1 Minus (0,1;1,1)-or 0 0 0 0 -1 -1 Minus (0,1)-xor 0 0 0 0 -1 0 … 0 0 0 0 -1 1 Minus (1,1)-and 0 0 0 0 0 -1 Zero 0 0 0 0 0 0 (1,1)-and 0 0 0 0 0 1 … 0 0 0 0 1 -1 (0,1)-xor 0 0 0 0 1 0 (0,1;1,1)-or 0 0 0 0 1 1 … 0 0 0 1 -1 -1 … 0 0 0 1 -1 0 … 0 0 0 1 -1 1 … 0 0 0 1 0 -1 (0,0)-and 0 0 0 1 0 0 (0,0;1,1)-or 0 0 0 1 0 1 … 0 0 0 1 1 -1 (0,0;0,1)-or 0 0 0 1 1 0 (-1)-nor 0 0 0 1 1 1 … 0 0 1 -1 -1 -1 … 0 0 1 -1 -1 0 … 0 0 1 -1 -1 1 … 0 0 1 -1 0 -1 … 0 0 1 -1 0 0 … 0 0 1 -1 0 1 … 0 0 1 -1 1 -1 … 0 0 1 -1 1 0 … 0 0 1 -1 1 1 … 0 0 1 0 -1 -1 … 0 0 1 0 -1 0 … 0 0 1 0 -1 1 … 0 0 1 0 0 -1 (-1,1)-xor 0 0 1 0 0 0 (-1,1;1,1)-or 0 0 1 0 0 1 … 0 0 1 0 1 -1 (-1,1;0,1)-or 0 0 1 0 1 0 (1)-or 0 0 1 0 1 1 … 0 0 1 1 -1 -1 … 0 0 1 1 -1 0 … 0 0 1 1 -1 1 … 0 0 1 1 0 -1 (-1,1;0,0)-or 0 0 1 1 0 0 … 0 0 1 1 0 1 … 0 0 1 1 1 -1 … 0 0 1 1 1 0 (-1,-1;-1,0)-nor 0 0 1 1 1 1 … 0 1 -1 -1 -1 -1 … 0 1 -1 -1 -1 0 … 0 1 -1 -1 -1 1 … 0 1 -1 -1 0 -1 … 0 1 -1 -1 0 0 … 0 1 -1 -1 0 1 … 0 1 -1 -1 1 -1 … 0 1 -1 -1 1 0 … 0 1 -1 -1 1 1 … 0 1 -1 0 -1 -1 … 0 1 -1 0 -1 0 … 0 1 -1 0 -1 1 … 0 1 -1 0 0 -1 … 0 1 -1 0 0 0 … 0 1 -1 0 0 1 … 0 1 -1 0 1 -1 … 0 1 -1 0 1 0 … 0 1 -1 0 1 1 … 0 1 -1 1 -1 -1 … 0 1 -1 1 -1 0 … 0 1 -1 1 -1 1 … 0 1 -1 1 0 -1 … 0 1 -1 1 0 0 … 0 1 -1 1 0 1 … 0 1 -1 1 1 -1 … 0 1 -1 1 1 0 … 0 1 -1 1 1 1 … 0 1 0 -1 -1 -1 … 0 1 0 -1 -1 0 … 0 1 0 -1 -1 1 … 0 1 0 -1 0 -1 … 0 1 0 -1 0 0 … 0 1 0 -1 0 1 … 0 1 0 -1 1 -1 … 0 1 0 -1 1 0 … 0 1 0 -1 1 1 … 0 1 0 0 -1 -1 … 0 1 0 0 -1 0 … 0 1 0 0 -1 1 … 0 1 0 0 0 -1 (-1,0)-xor 0 1 0 0 0 0 (-1,0;1,1)-or 0 1 0 0 0 1 … 0 1 0 0 1 -1 (-1,0;0,1)-or 0 1 0 0 1 0 … 0 1 0 0 1 1 … 0 1 0 1 -1 -1 … 0 1 0 1 -1 0 … 0 1 0 1 -1 1 … 0 1 0 1 0 -1 (-1,0;0,0)-or 0 1 0 1 0 0 … 0 1 0 1 0 1 … 0 1 0 1 1 -1 … 0 1 0 1 1 0 (-1,-1;-1,1)-nor 0 1 0 1 1 1 … 0 1 1 -1 -1 -1 … 0 1 1 -1 -1 0 … 0 1 1 -1 -1 1 … 0 1 1 -1 0 -1 … 0 1 1 -1 0 0 … 0 1 1 -1 0 1 … 0 1 1 -1 1 -1 … 0 1 1 -1 1 0 … 0 1 1 -1 1 1 … 0 1 1 0 -1 -1 … 0 1 1 0 -1 0 … 0 1 1 0 -1 1 … 0 1 1 0 0 -1 … 0 1 1 0 0 0 … 0 1 1 0 0 1 … 0 1 1 0 1 -1 … 0 1 1 0 1 0 (-1,-1;0,0)-nor 0 1 1 0 1 1 … 0 1 1 1 -1 -1 … 0 1 1 1 -1 0 … 0 1 1 1 -1 1 … 0 1 1 1 0 -1 … 0 1 1 1 0 0 (-1,-1;0,1)-nor 0 1 1 1 0 1 … 0 1 1 1 1 -1 (-1,-1;1,1)-nor 0 1 1 1 1 0 (-1,-1)-nand 0 1 1 1 1 1 … 1 -1 -1 -1 -1 -1 … 1 -1 -1 -1 -1 0 … 1 -1 -1 -1 -1 1 … 1 -1 -1 -1 0 -1 … 1 -1 -1 -1 0 0 … 1 -1 -1 -1 0 1 … 1 -1 -1 -1 1 -1 … 1 -1 -1 -1 1 0 … 1 -1 -1 -1 1 1 … 1 -1 -1 0 -1 -1 … 1 -1 -1 0 -1 0 … 1 -1 -1 0 -1 1 … 1 -1 -1 0 0 -1 … 1 -1 -1 0 0 0 … 1 -1 -1 0 0 1 … 1 -1 -1 0 1 -1 Modulus of difference 1 -1 -1 0 1 0 … 1 -1 -1 0 1 1 … 1 -1 -1 1 -1 -1 … 1 -1 -1 1 -1 0 … 1 -1 -1 1 -1 1 … 1 -1 -1 1 0 -1 … 1 -1 -1 1 0 0 … 1 -1 -1 1 0 1 … 1 -1 -1 1 1 -1 … 1 -1 -1 1 1 0 … 1 -1 -1 1 1 1 … 1 -1 0 -1 -1 -1 … 1 -1 0 -1 -1 0 … 1 -1 0 -1 -1 1 … 1 -1 0 -1 0 -1 … 1 -1 0 -1 0 0 … 1 -1 0 -1 0 1 … 1 -1 0 -1 1 -1 … 1 -1 0 -1 1 0 … 1 -1 0 -1 1 1 … 1 -1 0 0 -1 -1 … 1 -1 0 0 -1 0 … 1 -1 0 0 -1 1 … 1 -1 0 0 0 -1 … 1 -1 0 0 0 0 … 1 -1 0 0 0 1 … 1 -1 0 0 1 -1 … 1 -1 0 0 1 0 … 1 -1 0 0 1 1 … 1 -1 0 1 -1 -1 … 1 -1 0 1 -1 0 … 1 -1 0 1 -1 1 … 1 -1 0 1 0 -1 … 1 -1 0 1 0 0 … 1 -1 0 1 0 1 … 1 -1 0 1 1 -1 … 1 -1 0 1 1 0 … 1 -1 0 1 1 1 … 1 -1 1 -1 -1 -1 … 1 -1 1 -1 -1 0 … 1 -1 1 -1 -1 1 … 1 -1 1 -1 0 -1 … 1 -1 1 -1 0 0 … 1 -1 1 -1 0 1 … 1 -1 1 -1 1 -1 … 1 -1 1 -1 1 0 … 1 -1 1 -1 1 1 … 1 -1 1 0 -1 -1 … 1 -1 1 0 -1 0 … 1 -1 1 0 -1 1 … 1 -1 1 0 0 -1 … 1 -1 1 0 0 0 … 1 -1 1 0 0 1 … 1 -1 1 0 1 -1 … 1 -1 1 0 1 0 … 1 -1 1 0 1 1 … 1 -1 1 1 -1 -1 … 1 -1 1 1 -1 0 … 1 -1 1 1 -1 1 … 1 -1 1 1 0 -1 … 1 -1 1 1 0 0 … 1 -1 1 1 0 1 … 1 -1 1 1 1 -1 … 1 -1 1 1 1 0 … 1 -1 1 1 1 1 … 1 0 -1 -1 -1 -1 … 1 0 -1 -1 -1 0 … 1 0 -1 -1 -1 1 … 1 0 -1 -1 0 -1 … 1 0 -1 -1 0 0 … 1 0 -1 -1 0 1 … 1 0 -1 -1 1 -1 … 1 0 -1 -1 1 0 … 1 0 -1 -1 1 1 Minus maximum 1 0 -1 0 -1 -1 … 1 0 -1 0 -1 0 … 1 0 -1 0 -1 1 … 1 0 -1 0 0 -1 … 1 0 -1 0 0 0 … 1 0 -1 0 0 1 … 1 0 -1 0 1 -1 … 1 0 -1 0 1 0 … 1 0 -1 0 1 1 … 1 0 -1 1 -1 -1 … 1 0 -1 1 -1 0 … 1 0 -1 1 -1 1 … 1 0 -1 1 0 -1 … 1 0 -1 1 0 0 … 1 0 -1 1 0 1 … 1 0 -1 1 1 -1 … 1 0 -1 1 1 0 … 1 0 -1 1 1 1 … 1 0 0 -1 -1 -1 … 1 0 0 -1 -1 0 … 1 0 0 -1 -1 1 … 1 0 0 -1 0 -1 … 1 0 0 -1 0 0 … 1 0 0 -1 0 1 … 1 0 0 -1 1 -1 … 1 0 0 -1 1 0 … 1 0 0 -1 1 1 … 1 0 0 0 -1 -1 … 1 0 0 0 -1 0 … 1 0 0 0 -1 1 … 1 0 0 0 0 -1 (-1,-1)-and 1 0 0 0 0 0 … 1 0 0 0 0 1 … 1 0 0 0 1 -1 … 1 0 0 0 1 0 … 1 0 0 0 1 1 … 1 0 0 1 -1 -1 … 1 0 0 1 -1 0 … 1 0 0 1 -1 1 … 1 0 0 1 0 -1 … 1 0 0 1 0 0 … 1 0 0 1 0 1 … 1 0 0 1 1 -1 … 1 0 0 1 1 0 … 1 0 0 1 1 1 … 1 0 1 -1 -1 -1 … 1 0 1 -1 -1 0 … 1 0 1 -1 -1 1 … 1 0 1 -1 0 -1 … 1 0 1 -1 0 0 … 1 0 1 -1 0 1 … 1 0 1 -1 1 -1 … 1 0 1 -1 1 0 … 1 0 1 -1 1 1 … 1 0 1 0 -1 -1 … 1 0 1 0 -1 0 … 1 0 1 0 -1 1 … 1 0 1 0 0 -1 … 1 0 1 0 0 0 … 1 0 1 0 0 1 … 1 0 1 0 1 -1 … 1 0 1 0 1 0 … 1 0 1 0 1 1 … 1 0 1 1 -1 -1 … 1 0 1 1 -1 0 … 1 0 1 1 -1 1 … 1 0 1 1 0 -1 … 1 0 1 1 0 0 … 1 0 1 1 0 1 … 1 0 1 1 1 -1 … 1 0 1 1 1 0 … 1 0 1 1 1 1 … 1 1 -1 -1 -1 -1 … 1 1 -1 -1 -1 0 … 1 1 -1 -1 -1 1 … 1 1 -1 -1 0 -1 … 1 1 -1 -1 0 0 … 1 1 -1 -1 0 1 … 1 1 -1 -1 1 -1 … 1 1 -1 -1 1 0 … 1 1 -1 -1 1 1 … 1 1 -1 0 -1 -1 … 1 1 -1 0 -1 0 … 1 1 -1 0 -1 1 … 1 1 -1 0 0 -1 … 1 1 -1 0 0 0 … 1 1 -1 0 0 1 … 1 1 -1 0 1 -1 … 1 1 -1 0 1 0 … 1 1 -1 0 1 1 … 1 1 -1 1 -1 -1 … 1 1 -1 1 -1 0 … 1 1 -1 1 -1 1 … 1 1 -1 1 0 -1 … 1 1 -1 1 0 0 … 1 1 -1 1 0 1 … 1 1 -1 1 1 -1 … 1 1 -1 1 1 0 … 1 1 -1 1 1 1 … 1 1 0 -1 -1 -1 … 1 1 0 -1 -1 0 … 1 1 0 -1 -1 1 … 1 1 0 -1 0 -1 … 1 1 0 -1 0 0 … 1 1 0 -1 0 1 … 1 1 0 -1 1 -1 … 1 1 0 -1 1 0 … 1 1 0 -1 1 1 … 1 1 0 0 -1 -1 … 1 1 0 0 -1 0 … 1 1 0 0 -1 1 … 1 1 0 0 0 -1 … 1 1 0 0 0 0 … 1 1 0 0 0 1 … 1 1 0 0 1 -1 … 1 1 0 0 1 0 … 1 1 0 0 1 1 … 1 1 0 1 -1 -1 … 1 1 0 1 -1 0 … 1 1 0 1 -1 1 … 1 1 0 1 0 -1 (1)-nor 1 1 0 1 0 0 (-1,1;0,1)-nor 1 1 0 1 0 1 … 1 1 0 1 1 -1 (-1,1;1,1)-nor 1 1 0 1 1 0 (-1,1)-xnor 1 1 0 1 1 1 … 1 1 1 -1 -1 -1 … 1 1 1 -1 -1 0 … 1 1 1 -1 -1 1 … 1 1 1 -1 0 -1 … 1 1 1 -1 0 0 … 1 1 1 -1 0 1 … 1 1 1 -1 1 -1 … 1 1 1 -1 1 0 … 1 1 1 -1 1 1 … 1 1 1 0 -1 -1 … 1 1 1 0 -1 0 … 1 1 1 0 -1 1 Minus Minimum 1 1 1 0 0 -1 (-1)-or 1 1 1 0 0 0 (0,0;0,1)-nor 1 1 1 0 0 1 … 1 1 1 0 1 -1 (0,0;1,1)-nor 1 1 1 0 1 0 (0,0)-nand 1 1 1 0 1 1 … 1 1 1 1 -1 -1 … 1 1 1 1 -1 0 … 1 1 1 1 -1 1 … 1 1 1 1 0 -1 (0,1;1,1)-nor 1 1 1 1 0 0 (0,1)-xnor 1 1 1 1 0 1 … 1 1 1 1 1 -1 (1,1)-nand 1 1 1 1 1 0 One 1 1 1 1 1 1

n-ary logic gates

n-ary logic gates transform n input numbers to a single output number.

Because of the symmetry (permutations of the inputs should not change the output), there are k(k+n-1)!/[n!(k-1)!] n-ary logic gates in base-k algebra.

For example, there are 35!/(3!2!) = 310 = 59049 ternary logic gates in ternary algebra.