K-Map to solve algebraic reduction - boolean

I need help verifying an algebraic expression using K-Map.
The expression I'm posting was actually done by my professor, but for practice purpose I wanted to use the K-Map to verify that the answer is correct.
-> X • Y + X' • Y • Z' + Y • Z =
-> X • Y •(Z + Z') + X' • Y • Z' + Y • Z =
-> X•Y•Z + X•Y•Z' + X'•Y•Z' + Y• Z =
-> X•Y•Z + Y•Z' • (X + X') + Y•Z =
-> X•Y•Z + Y•Z' + Y•Z =
-> X•Y•Z + Y•(Z' + Z) =
-> X•Y•Z + Y=
-> Y•(X•Z + 1)= Y
When I tried my K-Map solution to prove the answer is correct, I came up with this
YZ' + X'Y
I'm not sure if my answer is correct or not. If it's not, I need someone to show me how to make it correct, so that it matches the solution I've posted. I appreciate the help.

Remember that a 1 goes into the K-map if and only if the expression doesn't change and match with either two 0s or two 1s. The expression does not exist when it changes or has a 0 and 1 together.
So this is my K-Map and what I did.
Kmap
My answer came up as Y, which also matches your professor's answer.
(Edit: I forgot to put the pluses in the equation, but I hope you get the idea)

The deduction and answer given by your professor is correct (every step is). Therefore your answer, being different, is not correct. Take for example the case X = Y = Z = 1. The original expression evaluates as follows
X • Y + X' • Y • Z' + Y • Z = 1 • 1 + 0 • 1 • 0 + 1 • 1
= 1 + 0 + 1
= 1
However,
Y • Z' + X' • Y = 1 • 0 + 0 • 1
= 0 + 0
= 0
which is different from the original expression and also from its equivalent Y.

You can break up the given function in the form of SOP (DNF) into separate terms and find them in the K-map. It is really like a crisscross.
Having the function:
f(x,y,z) = x·y + ¬x·y·¬z + y·z
where:
x·y ~ cells, where the x is true and the y is true; marked red;
¬x·y·¬z ~ cells, where the x and z are false and the y is true; marked blue; because it is using all the given variables, this term is also an minterm marking out only a single cell;
y·z ~ cells, where both y and z are true; marked green.
You can see, that the marked cells can be grouped into bigger 2^i sized bubble, a 2^2=4 one.
And you should use that instead of having the three products in the original function, because the less the variables and operators the easier to work with the expression.
Circling the largest possible group, you get the same result as your teacher.
f(x,y,z) = x·y + ¬x·y·¬z + y·z = y
As you can see now the expression logical value is in 50 percent of cases evaluated as true and in other 50 percent false, because the value depends only on the value of variable y.

Related

Formula to obtain amount to add to Starting Value so the added amount will = 5% of New Total

Is there a formula that will work in T-SQL that can obtain the following?
Solve for x where adding x to starting value, will equal 105% of starting value.
Example
Starting value of 380.
Add x to 380 so that x is 5% of total (380 + x)
In this case, x is an even 20.
This is not 5% of the Starting value, which, would be simple. I'm looking for x to equal 5% of the new value after it's been added to the starting value.
Thank you!
I'm looking for x to equal 5% of the new value after it's been added to the starting value.
Let's do some 9th grade algebra :) I'll even show my work.
If S is the starting value, we have this equation:
x = 0.05 * (S + x)
Now solve for x:
x = 0.05S + 0.05x // distribute the constant
0.95x = 0.05S // subtract the smaller x term from both sides
x = (0.05 / 0.95) * S // divide the 0.95 from both sides
x = S / 19 // multiply the right side by 1 (20/20) to simplify
So we see you can divide the starting value by 19 to get the desired x value.
And an alternative way to solve the equation, because I think this kind of thing is fun:
x = (1/20) * (S + x) // convert the decimal to a fraction
x = (S + x) / 20 // reduce/simplify the fraction multiplication
20x = S + x // multiply both sides by 20, to remove division
19x = S // subtract the smaller x term from both sides
// (hey, we solved for S along the way)
x = S / 19 // Divide both sides by 19
It's always nice when two approaches give the same solution :). This was more steps, but the steps were simpler.

how to prove that the hash function h(x) = x² mod 4 yields only to 0 and 1

How can I prove that the hash function h(x) = x² mod 4 yields only to {0, 1}, with x as an element of the natural numbers?
Let's first cover the even numbers, 2n (where n is a natural number):
(2n)2
= (2n)(2n)
= (2)(n)(2)(n)
= (2)(2)(n)(n)
= 4n2
= 4(n2)
That's an exact multiple of four so the remainder when dividing by four will always be zero.
Now let's cover the odd numbers, 2n + 1:
(2n + 1)2
= (2n + 1)(2n + 1)
= (2n)(2n) + (2n)(1) + (1)(2n) + (1)(1)
= 4n2 + 2n + 2n + 1
= 4n2 + 4n + 1
= 4(n2 + n) + 1
That's exactly one more than a multiple of four hence the remainder when dividing by four will always be one.
Now, let's look at any natural numbers that are neither even nor odd.
Wait a minute, there aren't any. I guess that means we're done :-)
And, before anyone points out that some languages may give a negative remainder when the arguments are negative, that doesn't actually apply here since the square of a natural number can never be negative.

Discrete Mathematics (Statement)

1) x^2 + x + 1 = 0 , x is a real number.
Answer: Is a statement.
2) x^2 + x + 1 = 0 , x is complex number.
Answer: Is not a statement.
Why the question no.2 is not a statment ?
To expand on Jiale's answer:
A statement is a statement which has a definite truth value.
1) x^2 + x + 1 = 0 , x is a real number.
This can be considered a statement because it is always false regardless of how x is chosen. This is because there is no real number which satisfies this equation. Therefore, it is guaranteed to have a definite truth value: false.
2) x^2 + x + 1 = 0 , x is complex number.
This cannot be considered a statement because it is true for some complex numbers x, and false for others. The truth value of this expression is only definite once x is specified. Therefore, it is not a statement.
Reason: A Statement is a declarative statement that is either true or false but not both.

Summing double variables in matlab [duplicate]

This question already has answers here:
Why is 24.0000 not equal to 24.0000 in MATLAB?
(6 answers)
Closed 5 years ago.
I'm having trouble summing 3 double numbers in MATLAB Command Window, here are my variables
>> a = 0.45;
>> b = 0.05;
>> c = -0.5;
when I sum them like this, I get 1.3878e-17
>> c + a + b
ans =
1.3878e-17
But when I use parentheses, it returns 0
>> c + (a + b)
ans =
0
Also summing them in this order returns 0 again
>> a + b + c
ans =
0
In usual storage of floats in programming languages using IEEE 754. Therefore, for storage of some floating numbers which cannot be shown by sum of some 2^i, there wouldbe some errors (in base 2) such as 0.3.
As mentioned in comments, you can use digits to find these errors:
digits(100);
vpa(a)
>> 0.4500000000000000111022302462515654042363166809082031250000000000000000000000000000000000000000000000
vpa(b)
>> 0.05000000000000000277555756156289135105907917022705078125000000000000000000000000000000000000000000000
vpa(c)
>> -0.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
vpa(a+b)
>> 0.5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
vpa(c+a)
>> -0.04999999999999998889776975374843459576368331909179687500000000000000000000000000000000000000000000000
As you can see in the above, because of this error, sum of a and c is not as exactly as you've expected (because of error in storage of floating points in base 2 in IEEE 754).
Therefore, there order of + is important as you found through these expressions. Hence, the preference of plus is from left to right, and preference of parenthesis is higher than plus, in the c + (a + b) and a + b + c, the a + b is done first,. Then, you can see the sum is exact in the above. However, in c + a + b, the c + a is happened sooner and you can see this sum is not exact, so the result of this sum with b could have some error.
In this way, you can find a + c + b is not exact as you want. And:
vpa(c + b)
>> -0.4500000000000000111022302462515654042363166809082031250000000000000000000000000000000000000000000000
So,
c + b + a
>> 0

Explain MATLAB function smooth(x,y,span,'moving')

I recently came across the Matlab smooth function used as follows:
ans = smooth(x, y, span, 'moving');
The Matlab documentation states
yy = smooth(x,y,...) additionally specifies x data. If x is not provided, methods that require x data assume x = 1:length(y). You should specify x data when it is not uniformly spaced or sorted. If x is not uniform and you do not specify method, lowess is used. If the smoothing method requires x to be sorted, the sorting occurs automatically.
However, I am unclear as to what this actually means for the 'moving' average case. Is x an index for the y data, and if so how do non-integer values of x affect the 'moving' average of y?
Moving average means each value of the yy (or ans in your case) is an average of the n closest points. https://en.wikipedia.org/wiki/Moving_average
There are several methods to calculate it - it depends on WHICH POINTS we will use. For example:
( (i-1) + (i-2) + ... + (i-n) )/n;
where n - is a span or linear filtration level.
This mean that first three points can't be calculated (there are no data for it). And sometimes result must be shifted (because really - average of the first 4 points not really corresponds to 4th elements).
So Matlab use another method:
yy(1) = y(1)
yy(2) = (y(1) + y(2) + y(3))/3
yy(3) = (y(1) + y(2) + y(3) + y(4) + y(5))/5
yy(4) = (y(2) + y(3) + y(4) + y(5) + y(6))/5
...
It's more useful.
About x and y - it is usual 2d-data: each x corresponds to each y. you can avoid setting of x, then matlab will use [1, 2, 3, ..., length(y)] sequence for this. But if you have some non-uniformly distributed data you have to set it for getting right result. So if you have non-integer values it will works correct, scaling it for x axis. Here the easiest example from my head:
Say you have data y corrupted by noise and let's assume y = [2.1, 3.2, 1.7, 4.5, 5.8, 6.9]. Let's say that you have decided to use moving average of 3 window filter to smooth y.
smoothedY1 = (2.1 + 3.2 + 1.7)/3 = 2.3333
smoothedY2 = (3.2 + 1.7 + 4.5)/3 = 3.1333
smoothedY3 = (1.7 + 4.5 + 5.8)/3 = 4.0000
smoothedY3 = (4.5 + 5.8 + 6.9)/3 = 5.7333
Pay attention to the way corrupted data is being shifted to the left by one element per iteration. Now let's use smooth() in Matlab.
y = [2.1, 3.2, 1.7, 4.5, 5.8, 6.9];
smooth(y, 3, 'moving')
The above script yields the following result
ans =
2.1000
2.3333 <----
3.1333 | (smoothed data)
4.0000 |
5.7333 <----
6.9000
To answer your original question, the "x" data is just used for sorting, but is otherwise ignored when the method is 'moving':
>> x = rand(10, 1);
>> y = (1:10)' + 0.1*randn(10,1);
>> isequal(smooth(x,y,'moving'), smooth(y,'moving'))
ans =
0
>> z = sortrows([x y], 1);
>> isequal(smooth(z(:,1),z(:,2),'moving'), smooth(z(:,2),'moving'))
ans =
1
The "x" values aren't actually taken into account for the averaging, they are just used to sort "y" by increasing index.