I have some problem simplifying the equation AB+A'B'= ? Is there any straight forward answer like AB'+A'B = A^B ; (^)=XOR sign ?
It's the XNOR function, which typically doesn't occur often enough to warrant its own operator. It's the negation of XOR, though, which can be seen by applying De Morgan's law twice.
AB + A'B' = ((AB)'(A'B')')'
= ((A' + B')(A + B))'
= (A'A + B'A + A'B + B'B)'
= (0 + AB' + A'B + 0)'
= (AB' + A'B)'
= (A ^ B)'
or by simply comparing truth tables
A B A ^ B AB + A'B'
-------------------------
0 0 0 1
0 1 1 0
1 0 1 0
1 1 0 1
(Put another way, XNOR is equivalence for two arguments, so you can think of A XNOR B as an operator that converts comparison to a value. A XNOR B equals 1 if A == B is true, 0 if it is false.)
Related
I've been struggling with boolean simplification in class, and took it to practice some more at home. I found a list of questions, but they don't have any answers or workings. This one I'm stuck on, if you could answer clearly showing each step I'd much appreciate:
Q=A.B.(~B+C)+B.C+B
I tried looking for a calculator to give me the answer and then to work out how to get to that, but I'm lost
(I'm new to this)
Edit: ~B = NOT B
I've never done this, so I'm using this site to help me.
A.B.(B' + C) = A.(B.B' + B.C) = A.(0 + B.C) = A.(B.C)
So the expression is now A.(B.C) + B.C + B.
Not sure about this, but I'm guessing A.(B.C) + (B.C) = (A + 1).(B.C).
This equals A.(B.C).
So the expression is now A.(B.C) + B.
As A.(B + C) = B.(A.C), the expression is now B.(A.C) + B, which equals (B + 1).(A.C) = B.(A.C).
NOTE: This isn't complete yet, so please avoid downvoting as I'm not finished yet (posted this to help the OP understand the first part).
Let's be lazy and use sympy, a Python library for symbolic computation.
>>> from sympy import *
>>> from sympy.logic import simplify_logic
>>> a, b, c = symbols('a, b, c')
>>> expr = a & b & (~b | c) | b & c | b # A.B.(~B+C)+B.C+B
>>> simplify_logic(expr)
b
There are two ways to go about such a formula:
Applying simplifications,
Brute force
Let's look at brute force first. The following is a dense truth table (for a better looking table, look at Wα), enumerating all possible value for a, b and c, alongside the values of the expression.
a b c -- a & b & (~b | c) | b & c | b = Q
0 0 0 0 0 10 1 0 0 0 0 0 = 0
0 0 1 0 0 10 1 1 0 0 1 0 = 0
0 1 0 0 1 01 0 0 1 0 0 1 = 1
0 1 1 0 1 01 1 1 1 1 1 1 = 1
1 0 0 1 0 10 1 0 0 0 0 0 = 0
1 0 1 1 0 10 1 1 0 0 1 0 = 0
1 1 0 1 1 01 1 0 1 0 0 1 = 1
1 1 1 1 1 01 1 1 1 1 1 1 = 1
You can also think of the expression as a tree, which will depend on the precedence rules (e.g. usually AND binds stronger than OR, see also this question on math.se).
So the expression:
a & b & (~b | c) | b & c | b
is a disjunction of three terms:
a & b & (~b | c)
b & c
b
You can try to reason about the individual terms, knowing that only one has to be true (as this is a disjunction).
The last two will be true, if and only if b is true. For the first, this a bit harder to see, but if you look closely: you have now a conjunction (terms concatenated by AND): All of them must be true, for the whole expression to be true, so a and b must be true. Especially b must be true.
In summary: For the whole expression to be true, in all three top-level cases, b must be true (and it will be false, if b is false). So it simplifies to just b.
Explore more on Wolfram Alpha:
https://www.wolframalpha.com/input/?i=a+%26+b+%26+(~b+%7C+c)+%7C+b+%26+c+%7C+b
A.B.(~B+C) + B.C + B = A.B.~B + A.B.C + B.C + B ; Distribution
= A.B.C + B.C + B ; Because B.~B = 0
= B.C + B ; Because A.B.C <= B.C
= B ; Because B.C <= B
This question already has answers here:
Divide two polynomials using MATLAB
(2 answers)
Closed 6 years ago.
I'm currently working on a Cyclic Code program for a class in MATLAB and I'm trying to figure out the best way to divide two polynomials, the generator P(X) and the user input, shifted by 3 (x^3 * D(X)) in order to get the Quotient Q(X) and Remainder C(X), which would allow me to get the transmitted data T(X) = X^3*D(X) + C(X)
The code I have for my program so far takes in the users 4-bit input in binary, i.e.
Insert 4-bit input: 1001
Then it checks it to make sure its valid, and shifts it giving:
0 0 0 1 0 0 1
which stands for the polynomial
X^3 + X^6
I then need to divide that by the generator polynomial
P(X) = 1 + X + X^3
Working it out on paper,
x^6 + X^3
___________
x^3 + x + 1
Gives: Q(X) = X^3 + X
R(X) = X^2 + X
So, T(X) = X^6 + X^3 + X^2 + X, which is 0111001 for the Codeword
What would be the best way to do this?
I have tried the following:
% Prompt for User input
b4_in = input('Insert 4-bit input: ' ,'s'); %Input 1001
%% CHECK FOR VAILD INPUT %%
dec_in = bin2dec(b4_in)
bin_in = fliplr(de2bi(dec_in)) %User input in Binary
d = [0000000]; %Calculating X^3 * D(X)
d = bin_in;
d(7)=0;
d = fliplr(d); %Gives 0 0 0 1 0 0 1
d
gen_pol = [1 1 0 1] %P(X) = 1 + X + X^3
[q, c] = deconv(bin_in, gen_pol)
When I go this, I get:
q =
1
c =
0 -1 0 0
What do I need to do differently to get the following?
q = 0 1 0 1
c = 0 1 1
Thank you!
In MATLAB, polynomials read in a binary vector from left to right. For example, x^3+x is [1 0 1 0], x^2+x is [1 1 0]. The Quotient Q(X) should be x^3-x instead of x^3+x. Make sure your inputs are in the right format, and you should get the following result as expected,
q =
1 0 -1 0
c =
0 0 0 0 1 1 0
i know that xor operator returns true if both its input differ but with this knowledge i cant understand various coding problem across the internet.
like these:
https://www.hackerearth.com/february-easy-16/algorithm/utkarsh-and-sub-array-xor-february-easy/
https://www.hackerrank.com/contests/hourrank-5/challenges/xor-se
pls help me understand these.
btw i use c++ for coding. explaining how to use XOR operator in these will be enough, no need to explain the full question.
An addition modulo 2 is equivalent to XOR.
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
equals to
( 0 + 0 ) mod 2 = 0
( 0 + 1 ) mod 2 = 1
( 1 + 0 ) mod 2 = 1
( 1 + 1 ) mod 2 = 0
Now you could use mod to solve XOR stuff.
There is no logical opertor xor in C/C++ and many other languages, only bitwise. It works separately for each corresponding bits of operands in there binary form.
I wanna ask some basic law of boolean algebra.
What i learn is :
1. A+A'B=A+B
2. A+AB'=A+B'
3. A+AB=A
4. A+A'B'=A+B'
but i meet some condition like :
A'+AB
so, what is the answer for A'+AB?
Let's say A' = D so when A is false, then D is true and vice versa.
Then A' + AB = D + D'B and if you understand your first equation:
D + D'B = D + B = A' + B
Regarding your comment:
I'll use this equality: AB + A'B = B and I will combine the first with the third and the second with the fifth term:
x'y'z'+x'yz+xy'z'+xy'z+xyz = y'z' + yz + xy'z
Now, from the result, I can do this:
y'z' + yz + xy'z = yz + y'(z' + zx)
and now, using using A' + AB = A' + B:
yz + y'(z' + zx) = yz + y'(z' + x) = yz + y'z' + y'x
or do this:
y'z' + yz + xy'z = y'z' + z(y+ xy') = y'z' + z(y + x) = y'z' + zy + xz
Are they different? No, take a look at this:
x y z | yz + y'z' + y'x | y'z' + zy + xz
0 0 0 | 1 | 1
0 0 1 | 0 | 0
0 1 0 | 0 | 0
0 1 1 | 1 | 1
1 0 0 | 1 | 1
1 0 1 | 1 | 1
1 1 0 | 0 | 0
1 1 1 | 1 | 1
You can use this open source project to solve basic boolean expression, its solve all the basic boolean expression
I have a 333x1 vector of values ('data') and each of the cells in the vector correspond to a range of 1 of 13 subcategories. The identities of each of these subcategories are stored in a separate identity matrix ('id'). I'd like to calculate the sum of the values within the original data matrix that have a similar identity.
e.g. pretending for this example that 'data' and 'id' are 8x1 vectors
data = [1;1;1;0;0;0;1;1]
id = [1;2;1;2;3;3;1;3]
sum of id 1: 1 + 0 + 1 + 0 + 0 + 0 + 1 + 0 = 3
sum of id 2: 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 = 1
sum of id 3: 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 = 1
I'm sure that there is a really easy fix for this, however I can't seem to work it out.
Thanks for your time
Mac
A simple solution would be:
numCategories = 13;
totals = zeros(numCategories,1);
for idnum = 1:numCategories
totals(idnum) = sum((id==idnum).*data);
end
EDIT: As knedlsepp pointed out in the comments, the accumarray function accomplishes exactly what the above code does in one line.
accumarray(id,data);