3

I am trying to find the lowest level of things that you just can't implement because they are too low level. So it seems that all computation can be constructed from the NAND gate.

enter image description here

From the truth table it is easy to "implement" in JavaScript:

function nand(a, b) {
  if (a == 0 && b == 0) return 1
  if (a == 0 && b == 1) return 1
  if (a == 1 && b == 0) return 1
  if (a == 1 && b == 1) return 0
}

But this is cheating. Because how are the IF statements implemented? I don't quite know how to represent that if-statement link in code since I'm not sure familiar with logic gates/circuits, but I am pretty sure the IF statement itself could be represented as a combination of NAND gates.

So then it's turtles all the way down! A NAND gate is implemented with more NAND gates (for the if-statements), etc..

So how do we avoid this situation? Do we simply say that a NAND gate is an axiom? I am wondering because I'm wondering where the foundation for formal verification lies.

Put another way, the reason I'm asking is because I've noticed that every function can be implemented as other functions, even the IF statement and such. Everything can be implemented all the way down to NAND gates. But then I am left swinging, the NAND is a function too, but what is it's implementation?!? I'm confused/perplexed and need some guidance on how to think about this.

Lance
  • 75,200
  • 93
  • 289
  • 503
  • what type of input do you want? – Nina Scholz Dec 25 '19 at 18:26
  • You know I am not really sure, whatever input makes this possible to define, either as an axiom or not. – Lance Dec 25 '19 at 18:27
  • 1
    There is a bottom. Logic circuits in hardware are physical devices. You can keep stacking layers of "emulate NAND using more NANDs" on top, but the bottom is still there, just further away now. By the way JavaScript `if` statements work *completely differently* from `if` in pure digital logic. – harold Dec 25 '19 at 20:54

1 Answers1

6

Since NAND is Not AND you can declare it using AND, which means that NAND is not an axiom:

function nand(a, b) {
  return !(a && b)
}

console.log(nand(false, false)) // true
console.log(nand(true, false)) // true
console.log(nand(false, true)) // true
console.log(nand(true, true)) // false

Using multiplication you can declare NAND with 0 and 1. Since AND is a * b (you get 1 if both are 1), NAND is 1 - a * b:

function nand(a, b) {
  return 1 - a * b
}

console.log(nand(0, 0)) // 1
console.log(nand(1, 0)) // 1
console.log(nand(0, 1)) // 1
console.log(nand(1, 1)) // 0
Ori Drori
  • 183,571
  • 29
  • 224
  • 209