Logic gates solving vs Simulations - boolean

Can anyone help me understand why is the output when you traced and solved using Boolean Algebra is different from Simulation softwares' output? I've traced it using boolean expression and the Q output is = a'+ c' while on simulations the Q output is = b'(a'+c'). Whenever I used Simulations the output in truth table is = 11001000 and whenever I traced and solved using boolean algebra my output in truth table is 11111010
The circuit in the second picture is what I'm referring to. ABC is my variables. The logic gates are NAND Gate, OR gate, NOT Gate, XOR Gate and NOR gate.
enter image description here
enter image description here

I simplified ((A*C)' ^ (C + B') + B)' as follows:
((A*C)' ^ (C + B') + B)'
|
| expand XOR
V
(A*C*(C + B') + (A' + C')*C'*B + B)'
|
|
V
(A*C + B*C' + B)'
|
|
V
(A*C + B)'
|
|
V
(A' + C')*B'

Related

How to simply (AB')' or (ABC')'?

Stuck on one aspect of a question for Computer Architecture I: Digital Design, and am not sure how to simplify (ABC')' or even (AB').
Not sure if any axiom or theorem can be applied, or if (ABC')' [or (AB')'] is the most simplified form. Can someone confirm?
You can splat (ABC')' into A' + B' + C; similarly, (AB')' is A' + B (according to De Morgan's laws). These are disjunctive normal form.
To expand upon what Amadan said:
(AB')' + (ABC')'
A' + B + A' + B' + C DeMorgan applie twice
A' + A' + B + B'+ C commutativity of disjunction
A' + B + B' + C x + x = x
A' + 1 + C x + x' = 1
1 + C x + 1 = 1
1 1 + x = 1
Upon reflection this must be the case since B must be either true or false, and each of these values makes one or the other of the original terms true.

How to simplify functions in matlab?

Hello Let's say I have theres two functions
F1= a*x^(2) + b
F2 = c*x
Where a, b and c are a constant and x is a variablem how do can I make matlab gives me a simplified version of F1*F2 so the answer may be
a*c*x^(3) + b*c*x
This is what I have in matlab
syms x a b c
F1 = a*x^(2) +b;
F2 = c*x^(2);
simplify(F1*F2)
ans =
c*x^2*(a*x^2 + b)
When I multiply in matlab it's just giving me (ax^(2) + b)(c*x)
Try this commands:
syms a x b c
F1= a*x^(2) + b
F2 = c*x
F=F1*F2
collect(F)
which will give you:
ans =
a*c*x^3 + b*c*x
The command collect is useful when working with polynoms. The opposite command is pretty. It will give you c*x*(a*x^2 + b)

Rewrite a symbolic expression in terms of a specific subexpression

I need to rewrite a symbolic expression in terms of a specific subexpression.
Consider the following scenario:
expression f with 2 variables a, b
subexpression c = a / b
syms a b c
f = b / (a + b) % = 1 / (1 + a/b) = 1 / (1 + c) <- what I need
Is there a way to achieve this?
Edit:
The step from 1 / (1 + a/b) to 1 / (1 + c) can be achieved by calling
subs(1 / (1 + a/b),a/b,c)
So a better formulated question is:
Is there a way to tell MATLAB to 'simplify' b / (a + b) into 1 / (1 + a/b)?
Just calling simplify(b / (a + b) makes no difference.
Simplification to your desired form is not automatically guaranteed, and in my experience, isn't likely to be achieved directly through simplify-ing as I've noticed simplification rules prefer rational polynomial functions. However,
if you know the proper reducing ratio, you can substitute and simplify
>> syms a b c
>> f = b / (a + b);
>> simplify(subs(f,a,c*b))
ans =
1/(c + 1)
>> simplify(subs(f,b,a/c))
ans =
1/(c + 1)
And then re-substitute without simplification, if desired:
>> subs(simplify(subs(f,a,c*b)),c,a/b)
ans =
1/(a/b + 1)
>> subs(simplify(subs(f,b,a/c)),c,a/b)
ans =
1/(a/b + 1)

Maple: specify variable over which to maximize

This is a very simple question, but found surprisingly very little about it online...
I want to find the minimizer of a function in maple, I am not sure how to indicate which is the variable of interest? Let us take a very simple case, I want the symbolic minimizer of a quadratic expression in x, with parameters a, b and c.
Without specifying something, it does minimize over all variables, a, b, c and x.
f4 := a+b*x+c*x^2
minimize(f4, location)
I tried to specify the variable in the function, did not work either:
f5 :=(x) ->a+b*x+c*x^2
minimize(f5, location)
How should I do this? And, how would I do if I wanted over two variables, x and y?
fxy := a+b*x+c*x^2 + d*y^2 +e*y
f4 := a+b*x+c*x^2:
extrema(f4, {}, x);
/ 2\
|4 a c - b |
< ---------- >
| 4 c |
\ /
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
extrema(fxy, {}, {x,y});
/ 2 2\
|4 a c d - b d - c e |
< --------------------- >
| 4 c d |
\ /
The nature of the extrema will depend upon the values of the parameters. For your first example above (quadratic in x) it will depend on the signum of c.
The command extrema accepts an optional fourth argument, such as an unassigned name (or an uneval-quoted name) to which is assigns the candidate solution points (as a side-effect of its calculation). Eg,
restart;
f4 := a+b*x+c*x^2:
extrema(f4, {}, x, 'cand');
2
4 a c - b
{----------}
4 c
cand;
b
{{x = - ---}}
2 c
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
extrema(fxy, {}, {x,y}, 'cand');
2 2
4 a c d - b d - c e
{---------------------}
4 c d
cand;
b e
{{x = - ---, y = - ---}}
2 c 2 d
Alternatively, you may set up the partial derivatives and solve them manually. Note that for these two examples there is just a one result (for each) returned by solve.
restart:
f4 := a+b*x+c*x^2:
solve({diff(f4,x)},{x});
b
{x = - ---}
2 c
normal(eval(f4,%));
2
4 a c - b
----------
4 c
fxy := a+b*x+c*x^2 + d*y^2 +e*y:
solve({diff(fxy,x),diff(fxy,y)},{x,y});
b e
{x = - ---, y = - ---}
2 c 2 d
normal(eval(fxy,%));
2 2
4 a c d - b d - c e
---------------------
4 c d
The code for the extrema command can be viewed, by issuing the command showstat(extrema). You can see how it accounts for the case of solve returning multiple results.

Subtracting two equal floating-point numbers in MATLAB is not equal 0

Suppose we want to calculate (a + b)2 in two different ways, that is
(a + b) * (a + b)
a2 + 2 a b + b2
Now, suppose a = 1.4 and b = -2.7. If we plug those two numbers in the formulas with format long we obtain in both cases 1.690000000000001, that is, if I run the following script:
a = 1.4;
b = -2.7;
format long
r = (a + b) * (a + b)
r2 = a^2 + 2*a*b + b^2
abs_diff = abs(r - r2)
I obtain
r = 1.690000000000001
r2 = 1.690000000000001
abs_diff = 6.661338147750939e-16
What's going on here? I could preview different results for r or r2 (because Matlab would be executing different floating-point operations), but not for the absolute value of their difference.
I also noticed that the relative error of r and r2 are different, that is, if I do
rel_err1 = abs(1.69 - r) / 1.69
rel_err2 = abs(1.69 - r2) / 1.69
I obtain
rel_err1 = 3.941620205769786e-16
rel_err2 = 7.883240411539573e-16
This only makes me think that r are not actually the same r2. Is there a way to see them completely then, if they are really different? If not, what's happening?
Also, both relative errors are not less than eps / 2, does this mean that an overflow has happened? If yes, where?
Note: This is a specific case. I understood that we're dealing with floating-point numbers and rounding errors. But I would like a to understand better them by going through this example.
Don't rely on the output of format long to conclude that two numbers are equal...
a = 1.4;
b = -2.7
r1 = (a + b) * (a + b);
r2 = a^2 + 2*a*b + b^2;
r3 = (a+b)^2;
Instead you can check their hex representation using:
>> num2hex([r1 r2 r3])
ans =
3ffb0a3d70a3d70d
3ffb0a3d70a3d710
3ffb0a3d70a3d70d
or the printf family of functions:
>> fprintf('%bx\n', r1, r2, r3)
3ffb0a3d70a3d70d
3ffb0a3d70a3d710
3ffb0a3d70a3d70d
or even:
>> format hex
>> disp([r1; r2; r3])
3ffb0a3d70a3d70d
3ffb0a3d70a3d710
3ffb0a3d70a3d70d
Floating point arithmetic is not associative.
While mathematically these two are equal, they are not in floating point maths.
r = (a + b) * (a + b)
r2 = a^2 + 2*a*b + b^2
The order operations are executed in floating point maths is very relevant. That is why when you do floating point maths you need to be very careful of the order of you r multiplications/divisions, specially when working with very big numbers together with really small numbers.