Boolean algebra assistance - boolean

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.

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.

Coq for HoTT: proving || P-> X || -> (P-> ||X||)

I need to prove in Coq that for any type X and any proposition P (though I think it should work even if P is a type) there exists
trunc_impl: || P-> X || -> (P-> ||X||)
where ||_|| is the symbol used in HoTT book to indicate propositional truncation.
I demonstrated the statement in type theory: one gets the thesis by using the induction principle of propositional truncation, assuming from an H : || P-> X || and a p: P that H=|H'|, with H': P->X , and then defines trunc_impl(p):= |H'(p)|.
(|-| indicates the constructor for the trucation, i.e. |_| : A -> ||A||).
By the way, I cannot write it in Coq!
Any help would be very appreciated.
I am using the HoTT library available on GitHub.
You need to Require Import Basics. since coq doesn't know Trunc.TruncType can be coerced to Type otherwise. The tactics that you want to be aware of are apply Trunc_ind which will act on a goal like forall (x : Tr _ _), _.
intros x y and revert x will come in handy to get the goal into a form you want to apply trunc_ind to .
You also have the (custom) tactic strip_truncations which will search the context for any terms that are wrapped up with a truncation and try to do induction on them to remove them. This requires the goal to be as truncated but that shouldn't be a problem here.
Finally, the constructor for truncations is tr, so you can use apply there.

Working out truth table for Boolean equation

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!

Logical instructions for CIL

How can I use logical operators like AND, OR, NOT in CIL ?
There are no CIL opcodes for those operators; you need to implement them via conditional branching instead. For instance, a && b is the same as a ? b : false, and a || b is the same as a ? true : b, both of which are relatively easy to implement in IL (e.g. you can use the brtrue opcode to do a conditional jump based on the value of a).