is it possible to simply this Boolean function
(!A*!B*!C) + (!A*!B*C*!D) + (A*!B*!C*D) + (A*!B*C*!D) + (A*B*!C*!D)
I came up with this:
(!B*(!A*(!C+!D))+A*(C XOR D)) + (A*B*!C*!D)
Messy to look at, but there are fewer terms.
Look at the truth table:
A B C D X
0 0 0 0 1
0 0 0 1 1
0 0 1 0 1
0 0 1 1 0
0 1 0 0 0
0 1 0 1 0
0 1 1 0 0
0 1 1 1 0
1 0 0 0 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0
1 1 1 0 0
1 1 1 1 0
It looks like you can take the three parts of the table where X = 1 and simplify this to the sum of three terms:
!A*!B*!(C*D) + A*!B*(C^D) + A*B*!C*!D
Note that I've use XOR (^) in the second term. If you can't use XOR then you'll need to expand the second term a little.
You can reduce the number of terms further by factoring out either !B or A for two of the terms, e.g.
!B*(!A*!(C*D) + A*(C^D)) + A*B*!C*!D
or:
!A*!B*!(C*D) + A*(!B*(C^D) + B*!C*!D)
Related
I need to make a function in lisp that counts the pieces in my board. Let me explain my issue/game:
i have a board (10x10) like so:
(
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
)
in this board we will represent two types of pieces:
1 by 1 squares
2 by 2 squares
they will be positioned in my board like so:
(
(0 1 0 0 0 0 0 1 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 1 1 0 0 0 0 0)
(0 0 0 1 1 0 0 1 1 0)
(0 0 0 0 0 0 0 1 1 0)
(0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
(0 1 0 0 0 0 1 0 0 0)
(0 0 0 0 0 0 0 0 0 0)
)
In this example I have four 1-by-1 squares and two 2-by-2 squares.
I need a function that counts how many of a given type of piece I have in my board.
Example:
(defun countPiece (board pieceType)
; here I am supposed to write my code
)
so if I called (countPiece (testBoard) 'twoByTwoSquare) it returns 2, for example where testboard is a function that returns a sample board with a few pieces positioned
However, I dont know where to begin. any tips?
EDIT: There can never be pieces together horizontally nor vertically. Only in diagonal
I am not fluent in lisp, so my answer will only give you the algorithmic solution:
singlePieces = empty list
doublePieces = empty list
for each row
for each column
if ((value[row][column] = 1)
and ((row - 1, column - 1) not in doublePieces)
and ((row - 1, column) not in doublePieces)
and ((row, column - 1) not in doublePieces)) then
if ((row < rowCount)
and (column < columnCount) and (value[row][column + 1] = 1)
and (value[row + 1][column] = 1)
and (value[row + 1][column + 1]) = 1) then
doublePieces.add(row, column)
else
singlePieces.add(row, column)
end if
end if
end for
end for
Here’s how to do it with lists:
(defun count-pieces (board &aux (small 0) (big 0))
(loop for (row next) on (cons nil board)
for bigs = nil then
(loop for (tl tr) on row
for (bl br) on (or next (mapcar (constantly 0) row)
for n from 0
for nearly-bigp = (every #’plusp (list tl tr bl br))
for bigp = nearly-bigp then (and nearly-bigp (not pbigp))
and pbigp = nil then bigp
for ninbig = (or (member n bigs) (and bigp (member (1+ n) bigs)))
if (and ninbig bigp)
collect n and collect (+ n 1)
and do (incf big)
else if ninbig do (incf small)))
(values big small))
I wrote this on my phone so I’m not sure it works. It’s also a little clumsy. It’s also probably worth using arrays instead of lists and it might be worthwhile to e.g. represent a big piece with -1 or 2 or 3 so that they may be easily distinguished.
I know that I can say convert a 2-input AND gate into a NOR gate by simply inverting the two inputs because of DeMorgan's Theorem.
But how would you do the equivalent on a 3-input AND gate?
Say...
____
A___| \
B___| )___
C___|____ /
I'm trying to understand this because my homework asks me to take a circuit and convert it using NOR synthesis to only use nor gates, and I know how to do it with 2 input gates, but the gate with 3 inputs is throwing me for a spin.
DeMorgan's theorem for 2-input AND would produce:
AB
(AB)''
(A' + B')'
So, yes, the inputs are inverted and fed into a NOR gate.
DeMorgan's theorem for 3-input AND would similarly produce:
ABC
(ABC)''
(A' + B' + C')'
Which is, again, inputs inverted and fed into a (3-input) NOR gate:
___
A--O\ \
B--O ) )O---
C--O/___ /
#SailorChibi has truth tables that show equivalence.
If i haven't made any mistakes it is pretty much the same, invert all 3 of the inputs and you get a NOR
Table:
AND with inverted in is exact the same as
1 1 1 = 1
1 1 1 = 0
1 0 1 = 0
0 1 0 = 0
0 1 1 = 0
0 1 0 = 0
0 0 1 = 0
0 0 0 = 0
NOR with original input
0 0 0 = 1
0 0 1 = 0
0 1 0 = 0
1 0 1 = 0
1 0 0 = 0
1 0 1 = 0
1 1 0 = 0
1 1 1 = 0
I have a fairly simple question that i cannot find an example of online. I understand that this can simplify to A^B but I have not yet covered that section. What is the correct value of the boolean expression (A'B + AB')?
Lets look at the truth table
A B A'B AB' A'B + AB'
-----------------------------
0 0 0 0 0
0 1 1 0 1
1 0 0 1 1
1 1 0 0 0
This simply computes the xor of A and B.
and hence this is our answer.
The definition of the symbol XOR (^) is a^b = a'b + ab', i.e. one or the other but not both must be true for the expression to be true. Therefore there are no intermediate steps to convert between the two expressions. This is because a'b and ab' are prime implicants of the boolean function.
Another (not necessarily more simplified) way to define XOR is (A+B).(A'+B')
A B A+B A' B' A'+B' (A+B).(A'+B')
----------------------------------------
0 0 0 1 1 1 0
0 1 1 1 0 1 1
1 0 1 0 1 1 1
1 1 1 0 0 0 0
I have a problem grasping the fact that A + AB = A and A(A + B) = A
Can anyone tell me how?
To understand this, look at the truth tables (1=true, 0=false):
"A" "B" "AB" "A+B" "A + AB" "A(A+B)"
0 0 0 0 0 0
0 1 0 1 0 0
1 0 0 1 1 1
1 1 1 1 1 1
I have a matrix of 0's and 1's, say:
0 1 0 0
0 0 1 0
1 0 0 0
I want to generate another matrix that replaces 0's with 1's and 1's with 0's:
1 0 1 1
1 1 0 1
0 1 1 1
Anyone know how to do this in Octave?
b = 1 - a;