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 fromif
in pure digital logic. – user555045 Commented Dec 25, 2019 at 20:54
1 Answer
Reset to default 8Since 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
版权声明:本文标题:javascript - How is the NAND gate implemented? (Conceptually) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741326329a2372502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论