Simplify boolean expression using two-input gates - boolean

I have a specific boolean expression L or M or N and I need to rearrange/simplify it using only NAND gates. I was able to simplify it into the form !L nand !M nand !N, but it could be understood as logical gate with three inputs.
How to convert the expression into two-input gates format. I have already tried to use brackets (!L nand !M) nand !N, but apparently this does not work (tried to check it in the given marking algorithm).

Related

in coq how to assume equality of two natural numbers

I want to use this definition to assume that certain equalities on the members of set R hold:
Definition wiring: Prop
(globalHasVoltage -> (voltageOf voltageIn) = vcc)
/\
(globalHasGround -> (
(voltageOf control) = zero
/\
(voltageOf ground) = zero
)
)
.
It seems coq distinguishes between Prop and bool, what are the differences, and how may i solve that issue?
Also If this definition implies some other definition (per say lets call it toBeEvaluated) and assuming that conversion between bool and prop can be done could this
Definition toBeEvaluated: Prop := (voltageOf voltageIn) = vcc.
be proven using unwraps and tauto. (In particular will it work with functions which have exact definitions)
The difference between Prop and bool is that definitions in Prop might be undecidable, while definitions in bool can always be computed (unless you use axioms). Many number types have bool and Prop equality operators, but R doesn't because equality in R is in principle undecidable, so one can't write an equality function for R which results in a bool. Imagine e.g. the equality of different infinite series which sum up to pi - one can't design a general algorithm which decides if two series result in pi or not. Electronics uses functions like sin which rely on such infinite series.
A few options / thoughts:
R is not a very appropriate type for signal levels. E.g. voltage levels like GND or VCC are not mathematically equal everywhere. You could e.g. work with ranges in Q to express signal levels.
Another appropriate type might be floating point numbers, which are supported by Coq (meanwhile also natively). Have a look at the coq-flocq package. For floating point numbers equality is decidable, but they won't be able to represent a voltage like 1.8V exactly.
Another option is to have an inductive type which has a few well known signal levels (GND, VCC, ...) but also a constructor for arbitrary R (either classic or constructive). At least for the well known levels equality would be decidable then, but not for the arbitrary levels.
Even though = is not decidable in R, you can usually proof equality of R expressions, e.g. using the ring or field tactic. But you can't prove automatically that say sin(pi/4)=cos(pi/4). Well of cause one can automate this as well, but such automation always will have limits. But this means that your equalities always need to be proven with tactics and can't be just computed.

"NAND only" vs "AND and NOT only" difference?

When you simplify something down into these two, is there really any difference between?
For example:
( (B'C)' * (B'D')' )'
Is this and NAND only? If so, can it be converted to AND and NOT only? Or vice-versa? I'm confused on the difference between the two.
Your formula:
( (B'C)' * (B'D')' )'
Assume ' is negation and * and juxtaposition are used for conjunction; disjunction is not shown but would be denoted +. Let us rewrite the formula using not and and instead:
not (not (not B and C) and not (not B and not D))
Let us also indicate which nots go with which ands:
not (not (not B and C) and not (not B and not D))
^1 ^2 ^2 ^1 ^3 ^3
We can therefore eliminate three nots and replace the corresponding ands with three nands:
(not B nand C) nand (not B nand not D)
We see right away that the original formula was not expressed using only nands since eliminating pairs of nots and ands using the definition of nand did not eliminate non-nand operators.
However, the original formula does consist only of and and not. Because any formula can be written using nands only, this one can. The lazy way is to just use not x = x nand x three times to remove each of the remaining nots.

implement boolean function using half adders and not gates

I received this question from my lecturer and i am stuck.
F=ca+b'a'
implement this function using no more than 3 H.A (half adder) and 3 NOT gates.
i succeed to get a'b' and ac
and still had 1 HA and 1 NOT gate.
I have difficulties creating the OR gate for those two.
Use De Morgan's law and convert the expression in the following form :- ((ca)'(b'a')')'. Assuming that complements of the Literals are available.
The actual implementation of the circuit.

NOR Gate from XOR and And

I am trying to create a 2-input NOR Gate only from XOR and AND Gates. however I am stuck. The output must be NOT X AND NOT Y as the definition of a NOR GATE but I can not seem to understand how to get it.
I think this will work.
(A XOR 1) AND (B XOR 1)

And operator Lisp

Why does and operator returns a value? What is the returned value dependent on?
When I try the following example -
(write (and a b c d)) ; prints the greatest integer among a b c d
where a, b, c and d are positive integers, then and returns the greatest of them.
However when one of a, b, c and d is 0 or negative, then the smallest integer is returned. Why is this the case?
As stated in the documentation:
The macro and evaluates each form one at a time from left to right. As soon as any form evaluates to nil, and returns nil without evaluating the remaining forms. If all forms but the last evaluate to true values, and returns the results produced by evaluating the last form. If no forms are supplied, (and) returns t.
So the returned value doesn't depend on which value is the "greatest" or "smallest" of the arguments.
and can be regarded as a generalization of the two-place if. That is to say, (and a b) works exactly like (if a b). With and in the place of if we can add more conditions: (and a1 a2 a3 a4 ... aN b). If they all yield true, then b is returned. If we use if to express this, it is more verbose, because we still have to use and: (if (and a1 a2 a3 ... aN) b). and also generalizes in that it can be used with only one argument (if cannot), and even with no arguments at all (yields t in that case).
Mathematically, and forms a group. The identity element of that group is t, which is why (and) yields t. To describe the behavior of the N-argument and, we just need these rules:
(and) -> yield t
(and x y) -> { if x is true evaluate and yield y
{ otherwise yield nil
Now it turns out that this rule for a two-place and obeys the associative law: namely (and (and x y) z) behaves the same way as (and x (and y z)). The effect of the above rules is that no matter in which of these two ways we group the terms in this compound expression, x, y, and z are evaluated from left to right, and evaluation either stops at the first nil which it encounters and yields nil, or else it evaluates through to the end and yields the value of z.
Thus because we have this nice associative property, the rational thing to do in a nice language like Lisp which isn't tied to infix operators is to recognize that since the associative grouping doesn't matter, let's just have the flat syntax (and x1 x2 x3 ... xN), with any number of arguments including zero. This syntax denotes any one of the possible associations of N-1 binary ands which all yield the same behavior.
In other words, let's not make the poor programmer write a nested (and (and (and ...) ...) ...) to express a four-term and, and just let them write (and ...) with four arguments.
Summary:
the zero-place and yields t, which has to do with t being the identity element for the and operation.
the two-place and yields the second value if the first one is true. This is a useful equivalence to the two-place if. Binary and could be defined as yielding t when both arguments are true, but that would be less useful. In Lisp, any value that is not nil is a Boolean true. If we replace a non-nil value with t, it remains Boolean true, but we have lost potentially useful information.
the behavior of the n-place and is a consequence of the associative property; or rather preserving the equivalence between the flat N-argument form and all the possible binary groupings which are already equivalent to each other thanks to the associative property.
One consequence of all this is that we can have an extended if, like (if cond1 cond2 cond3 cond4 ... condN then-form), where then-form is evaluated and yielded if all the conditions are true. We just have to spell if using the and symbol.