Working out truth table for Boolean equation - boolean

I am trying to work out the truth table for the Boolean Equation that I am badly explaining:
[A.B (NAND)] + [A+B (NOT NOR]
I would also be interested to know how I represent this equation properly using a standard character set. Help!

The syntax in many programming languages is similar to the following
AND:
A && B
OR:
A || B
NOT:
!A
NAND:
!(A && B)
NOR:
!(A||B)
Hope that helps. If you have any questions don't hesitate to comment below!

Related

Convention for Checking Equivalence of Three Values (Python)

I had a question re: checking for equivalence of three values in Python. I was wondering which of these two options was better, as in, is one a more excepted convention than the other?
a == b == c
a == b and b == c
Any insight would be appreciated, thank you!

How does a missing boolean operator still compile?

I have code like this:
val pop: Bool = (
(fsm === Fsm.None && canPop) ||
(fsm === Fsm.Some && canPop && fooBar)
(fsm === Fsm.Other && canPop && dragonFruit) ||
(fsm === Fsm.Mom && canPop))
fsm is a ChiselEnum based state machine and the other signals are just Bools. There is a missing || on the second statement line (after fooBar). This compiles and runs, although causes a bug in the behavior. My question is... why does this compile? This doesn't seem like valid syntax. Is it?
Please help me understand this. I just spent numerous days debugging a large circuit to find this issue.
Correct Answer
The problem is that this is a bit extract. Chisel lets you do foo(bar) to extract the bit at index bar out of foo. The above code, as written, is a bit extract even though the user wants it to be a mistake.
Unfortunately, this is a known gotcha and it's not reasonable to error on this without false positives while still allowing users to use the () syntax for bit extracts.
Incorrect Original Answer
It's valid syntax per Scala rules. What's going on here is that the code is really two statements, but the indentation is confusing. It's equivalent to:
val foo = a + b // Create an immutable value equal to "a + b".
c + d // A bare statement that adds "c + d", but doesn't use the result.
Or infamous C bugs like:
if (cond)
foo();
bar(); // bar() is always executed, but the indentation is confusing.
Usually this is the type of thing that you'd notice due to a code formatter or via linting. However, the problem is common to almost every language.
Setting up Scalafmt for your project may help.

Boolean expression with a redundant overlapping term

I have simplified a Boolean expression using 14 Boolean Algebra law steps and now have a working resultant function which according to a KV map still has a redundant term.
In an attempt to remove this term I have tried various distribution, complement and identity applications followed by a deMorgans law, as well a Consensus Theorem approach. Of the text books I've consulted they all say there is no theory or set rules to resolving such an issue, just experience!
After much simplification (page and half) my resultant expression is,
z = ~a~cd + b~a + b~d + bc [1]
Using a KV map I get a slightly simpler expression of,
z = ~a~cd + b~d + bc [2]
The truth table of each expression is equivalent therefore the b~a of my first expression [1] appears to be redundant.
I expected to be able to cancel the redundant **b~a** function by applying the laws of Boolean algebra but after much experimenting I'm unable to find an entry point.
This is an assignment question so I do not expect anybody to do my homework but advise on how to approach this challenge would be appreciated.

Does pyDatalog have a "cut" operator like prolog?

This may be quite simple, but i can't find the answer anywhere. In Prolog, when you want to prevent it from searching for additional answers, once a variable has already been instantiated, you can use the ! sign (usually called the "cut" sign).
You can see it in this link to understand what i mean:
http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse44
for example, given the rule:
max(X,Y,Z) :- X =< Y,!, Y = Z.
if we query:
max(X,Y,X).
the ! sign will prevent prolog from backtracking and trying to prove (X =< Y) by re-instantiating X. This means that all answers will have the same value for X in them.
Is there something like this in pyDatalaog?
No, it doesn't have the cut operator. Cut is not part of Datalog, in general.
However, pyDatalog stops after finding the first value for given arguments of a function. The reference page says : "a function should be defined with the most general clause first, and more specific clauses next. When querying a function, the last one is used first, and the query stops when an answer is found."
So, you may get what you need with the following definition:
+ (max[X,Y] == Y)
(max[X,Y] == X) <= (Y < X)
Note however that there is an open issue.

Boolean algebra assistance

I'm confused. Is this the same?
!A && !B = !(A && B)?
Or is it = !(A || B)?
create a truth table and see for yourself
!A && !B = !(A || B)
This is one of "DeMorgan's Laws".
As a rule of thumb, I like to remember DeMorgan's laws with a quote I once read: "Do what you hate or find difficult; that is the sign of a strong person. Weak people only do what they like and find easy." (emphasis mine). This is a real-life application of DeMorgan's laws.
In general, you can find these things out by creating a truth table.