Turing Complete

Turing Complete

55 个评价
De Morgan's Law or How to NAND
由 Doodelinquent 制作
A small guide on De Morgan's Law.
It will allow you to replace NAND gates with AND, OR and NOT gates - or to replace these with NAND gates.
Using De Morgan's Law you can reduce your gate count in some situations, which could even help you with getting some achievements.
2
   
奖励
收藏
已收藏
取消收藏
Disclaimer
This is not some super expert guide.
If you "know" boolean logic this will not do anything for you (I'm sorry).

It is meant to help out people playing this game, who are not too knowledgable regarding boolean logic.
Notation
Following, I will use these symbols:
∧ - AND
∨ - OR
¬ - NOT
⊼ - NAND
⊽ - NOR

[a NAND b] is equals to combining a and b with AND and negating the whole term:
a ⊼ b = ¬ (a ∧ b)

The same is true for NOR regarding OR:
a ⊽ b = ¬ (a ∨ b)
De Morgan's Law
De Morgan's Law allows replacing AND and OR with each other under specific circumstances.
¬ (a ∧ b) = ¬a ∨ ¬b
¬ (a ∨ b) = ¬a ∧ ¬b
So, if you have [a AND b] negated as a whole [NOT (a AND b)] you can rewrite it by "dragging" the negation into the term (make a ¬a and b ¬b) and replacing AND with OR.
This applies to [a OR b] as well (you just have to replace the OR with AND instead).

As you might have noticed ¬ (a ∧ b) is nothing else than a NAND b.
That means:
a ⊼ b = ¬a ∨ ¬b
a ⊽ b = ¬a ∧ ¬b

You can of course verify this by booting up Turing Complete and placing down both [a NAND b] and [(NOT a) or (NOT b)].
Reducing gate count using De Morgan's Law
As you probably know double negation has no effect.
¬¬ a = a

You can use this in conjunction with De Morgan's Law to reduce your gate count, if applicable.
Just have a closer look any time you use a lot of NOT-gates - you might be able to get rid of some of them.

For example ¬(¬a ∨ ¬b) uses 4 gates.
¬(¬a ∨ ¬b) = (¬¬a ∧ ¬¬b) = (a ∧ b)
Now it only uses a single AND gate.

[¬a ∨ ¬b] uses 3 gates.
But you can replace all 3 of those gates with just a single NAND:
[¬a ∨ ¬b] = [¬ (a ∧ b)] = [a ⊼ b]
(see Morgan's Law section, this is the same term as the definition there).

Errors? Improvements?
If you found any errors or have any improvements please leave a comment.
12 条留言
kenpeter 2024 年 2 月 13 日 上午 11:30 
Imagine a crazy world with no inverting gates. All you need is an evil opposite machine to trade wires with. So you build the good half of AND, and the evil half of OR (with negative true logic). Almost twice as many gates, but wireswap inversions cost no gate or time.

Dunno if you ever heard of Majority gate (best two out of three, calculates Carry). Bias vote A low: takes B AND C to overrule. Biased high: B OR C or both might agree. Majority vote with all inputs and output inverted (DeMorgan'd) is still the same Majority vote and its own evil opposite.
ShiaNox 2022 年 9 月 25 日 下午 11:02 
The easy way would be to simply state:
negating all inputs and outputs also negates the operator (for ∨ and ∧) like
¬(¬a ∨ ¬b) = a ∧ b
So if you can use AND, OR, NAND, and NOR the only point to using it would be if any has both inputs negated. (I had to search for De Morgan's Law as that behavior was common sense to me or at least, I couldn't remember ever hearing of it.)
Doodelinquent  [作者] 2022 年 2 月 21 日 上午 5:38 
That really sounds like the perfect spot to use it!
Happy to help :)
deathangel 2022 年 2 月 20 日 下午 2:31 
Thanks for the guide!

I was hunting for an answer like this after I finished a level where I needed to AND a couple of bytes but didn't have a byte level AND gate. Only byte level OR and NOT gates.

So, instead I ended up exploding out the bits and AND-ed them individually. I figured there was a more elegant solution and saw someone accomplish the same thing using the byte level OR and NOT gates. I didn't understand how they knew to do that, or what was happening until I came across this explanation. Thanks!
levet.byck 2022 年 2 月 10 日 下午 4:15 
good luck with it :)
Doodelinquent  [作者] 2022 年 2 月 8 日 上午 4:10 
I'm thinking about creating a mini series of guides introducing beginners to boolean algebra.
The series would include an easier to understand version of this guide..
I'd appreciate some input on how I could go about improving this guide.
Right now I'm mostly thinking about adding images showing the corresponding circuits and maybe using an easier to understand notation (Not, And, Or instead of ¬, ∧, ∨).
levet.byck 2022 年 2 月 6 日 上午 3:13 
wow, i think using these notations could help when getting your head full when trying to memorise a sequence from an input
Mr. Doucet 2021 年 11 月 30 日 上午 3:13 
https://www.youtube.com/c/nesoacademy
Search Boolean Algebra
Mr. Doucet 2021 年 11 月 30 日 上午 3:12 
https://www.youtube.com/c/nesoacademy

Go to playlist ----> Digital Electronics. Better than college.
Doodelinquent  [作者] 2021 年 10 月 13 日 上午 8:04 
Thank you two for the kind words!

@veeddubb Unfortunately I can't really help you with that. I have to admit I am not too experienced in boolean algebra myself.
If you can't find a good source I would recommend looking up kind of a cheat sheet with "all the laws" and practising those by just applying them to different boolean expressions (and then checking that the expressions are equal).

However there's one thing that I would highly recommend to you: Karnaugh maps. They will allow you to simplify your circuits / boolean expressions (though they will exclusively use AND, OR and NOT gates rather than using NAND and alike - so you might be able to further reduce the gate count if you use these). Make sure you know about the "disjunctive normal form" before looking up Karnaugh Maps (and while you're at it you might want to take a look at the "disjunctive normal form", just for good measure).

I hope this was at least somewhat useful to you. If you find a great source, let me know.