Boolean Expression for 4 input Logic gates - boolean-logic

I have 4 inputs; (A, B, C, D) and 3 outputs; (X,Y,Z).
1)X is true when the input is less than 0111.
2)Y is true when the input is greater than 0111.
3)Z is true when the input is 0111.
Can someone help me out with the Boolean Expression for X?
I have already obtained the expressions for Y and Z which are as follows:
Y = A
_
Z = A . (B . C . D)

X is true when neither Y or Z are true:
_ _
X = Y + Z
or
_____
X = Y . Z
The expansion of which can be simplified, hint:
_ _ _
A + A = A
From first principles, any expression can be obtained from the truth table by OR'ing the true AND expression for each row that has a true result (then simplifying where possible); for example:
A B C X
--------- _ _ _
0 0 0 1 = A . B . C
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 1 = A . B . C
_ _ _
X = (A . B . C) + (A . B . C)
alternatively:
_________
X = (A + B + C) + (A . B . C)
For large truth tables, this can become cumbersome (which is why my example has only three variables), in these cases a Karnaugh Map could be used instead.

Related

What is the correct way to simplify a xnor

I was reading over a resource https://www.mi.mun.ca/users/cchaulk/misc/boolean.htm and I noticed the xnor simplification seems to have mixed outputs.
15a, 15b, 15c are all focusing on xnor but only 15b seems to be correct when I attempt to check.
For reference:
15a = (X + Y) • '(X • Y)
15b = 'X'Y + XY
15c = (X + Y) • ('X + 'Y)
The expected truth table for all of them are:
x
y
output
0
0
true
0
1
false
1
0
false
1
1
true
But only 15b is giving that as the truth table.
Am I solving 15a,15c incorrectly or is the resource incorrect?
15b is the definition of XNOR in conjunctive normal form. 15c is the negation of XNOR (i.e., XOR) in disjunctive normal form. You can derive this using De Morgan's laws, which state
'(XY) == 'X + 'Y
'(X + Y) == 'X'Y
Using these laws, we can first write 15b
'X'Y + XY = '('('X'Y)'(XY))
= '((X + Y)('X + 'Y))
to get the negation of 15c. Using it again, we get the negation of 15a.
= '(X + Y) + '('X + 'Y)
= '(X + Y) + XY
= '((X+Y) '(XY))

program in any language Numerical methods

To estimate the absolute and relative error of the calculation of the F value under
condition of:
A) the given exact numbers of the entered values of the arguments are x1 , x2 , x3
B) the given values of arguments x1 , x2 , x3 with the error ϵ = N⋅10-3, where N is the
variant number
Variant 1
F = 2⋅x1 2 + 3⋅x2 2 + x3 2 + 4⋅x1⋅x2 – 3⋅x3 + cos(x2 - x1)
Variant 2
F = 5⋅x1 2 + 3⋅x2 2 + 2⋅x3 2 - 4⋅x2⋅x3 - 2⋅x1 – cos(x2⋅x3);

How to display zero values in mysql query?

This code make an operation on a and b and check if result is equal to c.
If yes, just print this row. My question is how to change this code to display
rows when result (a / b) = 0.
SELECT id, a, b, operation, c
FROM expressions
where
case
when operation LIKE '+' AND (a + b = c) then c
when operation LIKE '-' AND (a - b = c) then c
when operation like '/' AND (a / b = c) then c
when operation like '*' AND (a * b = c) then c
ELSE FALSE END;
Output:
id a b operation c
1 2 3 + 5
4 4 7 * 28
11 0 1 / 0
14 239 0 * 0
15 18 18 - 0
1, 2 rows are ok and printed. 3, 4, 5 rows should be printed but they are not!
When a / b = 0 then second condition in sql query is false - row is not printed, e.g. 0 / 1 = 0. It is 0 and should be printed. In contrart to 1 / 0 which shouldn`t be printed.
My solution is to cast (a / b = c) to unsigned but it is not working?
You shouldn't mix types like boolean and int because implicit conversion occurs.
Use explicit value instead of TRUE/FALSE (0 is treated as FALSE).
SELECT id, a, b, operation, c
FROM expressions
where
case
when operation LIKE '+' AND (a + b = c) then 1
when operation LIKE '-' AND (a - b = c) then 1
when operation like '/' AND (a / b = c) then 1
when operation like '*' AND (a * b = c) then 1
ELSE 0 END = 1;
alternatively:
SELECT id, a, b, operation, c
FROM expressions
where
case
when operation LIKE '+' AND (a + b = c) then TRUE
when operation LIKE '-' AND (a - b = c) then TRUE
when operation like '/' AND (a / b = c) then TRUE
when operation like '*' AND (a * b = c) then TRUE
ELSE FALSE END;
As already pointed out, the issue is that 0 is treated as false.
I would simplify the logic to:
SELECT id, a, b, operation, c
FROM expressions
WHERE (operation LIKE '+' AND (a + b = c) ) OR
(operation LIKE '-' AND (a - b = c) ) OR
(operation LIKE '/' AND (a / b = c) ) OR
(operation LIKE '*' AND (a * b = c) );
I don't think the CASE makes the code more understandable.
If you are concerned about divide-by-zero, then use nullif():
(operation LIKE '/' AND (a / nullif(b, 0) = c) ) OR

Boolean Algebra, meaning of this sign...?

What does the equivalence sign with the small 3 next to it mean... I'm unfamiliar with that sign.
≡3
Thanks!
This means "is congruent to modulo 3." For example, 7 ≡3 1 because 7 mod 3 = 1 = 1 mod 3. More formally, a ≡n b iff there exists integral c0, c1, along with an integral k with 0 ≤ k < n, such that a = nc0 + k and b = nc1 + k.

Convert byte to specific mask with bit hack

I have number with binary representation 0000abcd.
How convert it to 0a0b0c0d with smallest number of operations?
How convert 0a0b0c0d back to 0000abcd?
I was searching for a solution here:
http://graphics.stanford.edu/~seander/bithacks.html and other
Generally the problem a bit more than described.
Given first number a₁b₁c₁d₁a₂b₂c₂d₂ and second number a₃a₄b₃b₄c₃c₄d₃d₄
If (a₁ and a₂ = 0) then clear both a₃ and a₄, if (a₃ and a₄ = 0) then clear both a₁ and a₂, etc.
My solution:
a₁b₁c₁d₁a₂b₂c₂d₂
OR 0 0 0 0 a₁b₁c₁d₁ ( a₁b₁c₁d₁a₂b₂c₂d₂ >> 4)
----------------
0 0 0 0 a b c d
? (magic transformation)
? ? ? ? ? ? ? ?
----------------
0 a 0 b 0 c 0 d
OR a 0 b 0 c 0 d 0 (0 a 0 b 0 c 0 d << 1)
----------------
a a b b c c d d
AND a₃a₄b₃b₄c₃c₄d₃d₄
----------------
A₃A₄B₃B₄C₃C₄D₃D₄ (clear bits)
UPDATED: (thanks for #AShelly)
x = a₁b₁c₁d₁a₂b₂c₂d₂
x = (x | x >> 4) & 0x0F
x = (x | x << 2) & 0x33
x = (x | x << 1) & 0x55
x = (x | x << 1)
y = a₃a₄b₃b₄c₃c₄d₃d₄
y = (y | y >> 1) & 0x55
y = (y | y >> 1) & 0x33
y = (y | y >> 2) & 0x0F
y = (y | y << 4)
work for 32-bit with constants 0x0F0F0F0F, 0x33333333, 0x55555555 (and twice long for 64-bit).
If you're looking for the smallest number of operations, use a look-up table.
I have number with binary
representation 0000abcd. How convert
it to 0a0b0c0d with smallest number of
operations?
Isn't this exactly "Interleave bits of X and Y" where Y is 0? Bit Twiddling Hacks has Multiple Solutions that don't use a lookup table.
How convert 0a0b0c0d back to 0000abcd?
See "How to de-interleave bits (UnMortonizing?)"
You can't do it in one go, you should shift bits on per bit basis:
Pseudo code:
X1 = a₁b₁c₁d₁
X2 = a₂b₂c₂d₂
Bm = 1 0 0 0 // Bit mask
Result = 0;
while (/* some bytes left */)
{
Result += (X1 and Bm) << 1 or (X2 and Bm);
Bm = Bm shr 1
Result = Result shl 2;
}
As a result you will get a1a2b1b2c1c2d1d2
I think it is not possible (without lookup table) to do it in less operations using binary arithmetic and x86 or x64 processor architecture. Correct me if I'm mistaken but your problem is about moving bits. Having the abcd bits you want to get 0a0b0c0d bits in one operation. The problem starts when you will look at how many bits the 'a','b','c' and 'd' has to travel.
'a' was 4-th, became 7-th, distance travelled 3 bits
'b' was 3-rd, became 5-th, distance travelled 2 bits
'c' was 2-nd, became 3-rd, distance travelled 1 bit
'd' was 1-st, became 1-st, distance travelled 0 bits
There is no such processor instruction that will move these bits dynamically to a different distance. Though if you have different input representations of the same number for free, for example you have precomputed several values which you are using in a cycle, than maybe it will be possible to gain some optimization, this is the effect you get when using additional knowledge about the topology. You just have to choose whether it will be:
[4 cycles, n^0 memory]
[2 cycles, n^1 memory]
[1 cycle , n^2 memory]