admin管理员组

文章数量:1287803

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 putation can be constructed from the NAND gate.

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 bination 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.

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 putation can be constructed from the NAND gate.

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 bination 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.

Share Improve this question edited Dec 25, 2019 at 18:26 Lance Pollard asked Dec 25, 2019 at 18:25 Lance PollardLance Pollard 79.5k98 gold badges330 silver badges607 bronze badges 3
  • what type of input do you want? – Nina Scholz Commented Dec 25, 2019 at 18:26
  • You know I am not really sure, whatever input makes this possible to define, either as an axiom or not. – Lance Pollard Commented Dec 25, 2019 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 pletely differently from if in pure digital logic. – user555045 Commented Dec 25, 2019 at 20:54
Add a ment  | 

1 Answer 1

Reset to default 8

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

本文标签: javascriptHow is the NAND gate implemented (Conceptually)Stack Overflow