Consider the 4-to-1 multiplexer shown below. What values must inputs A, B, C, D be so that the multiplexer implements the function - boolean-logic

I am completing some practice quizzes online in preperation for a uni exam next week, and I am a bit stumped as to how to solve this problem:
Consider the 4-to-1 multiplexer shown below. What values must inputs
A, B, C, D be so that the multiplexer implements the function
If anyone would'nt mind giving me a few tips as to how to solve this, I would much appreciate it.
Thanks
Corey

I'll assume: X = S1 * ~S0 + S0 * ~S1 as your posted picture is unreadable.
First you need to know the multiplexor transfer:
S1 S0 X
0 0 A
0 1 B
1 0 D
1 1 C
Then, apply the function to all your possible input combinations.
f(s1,s0)=S1*~S0+~S1*S0
f(0,0) = 0
f(0,1) = 1
f(1,0) = 1
f(1,1) = 0
And finally fill the table with X=f(s1,s0)
S1 S0 X f(s1,s0)
0 0 A 0
0 1 B 1
1 0 D 1
1 1 C 0

Related

Special cases of modulo operator

I included a function (a%b + b) % b in some old cold and remember concluding that this was due to some special cases of a%b that I needed to be careful about. a and b are c ints and % is the c modulo operator. Now I am having trouble seeing where these two expressions ever differ. Are they completely equivalent?
The mathematical long division demands that the remainder is zero or positive, a=q*b+r with 0 <= r < b.
In the computer implementations of this operation it is possible that a%b is negative. Thus adding b then gives the non-negative remainder. To be universally useful you either need an if-branching or another remainder operation for the case where a%b already was non-negative.
The % operator does not implement a true modulo. In fact,
a ≥ 0 -> a % b = a mod b
a < 0 -> a % b = - ((-a) mod b)
Now,
a -4 -3 -2 -1 0 1 2 3 4
a mod 4 0 1 2 3 0 1 2 3 0
a % 4 0 -3 -2 -1 0 1 2 3 0
(a % 4 + 4) % b 0 1 2 3 0 1 2 3 0
Unfortunately, this doubles the cost of the modulo, which is significant.

Generate Permutations using Hunspell affix rules

The bounty expires in 2 days. Answers to this question are eligible for a +50 reputation bounty.
shantanuo wants to draw more attention to this question.
let's assure there is a new language where a combination of 3 letters in any order are valid. For e.g. abc, acb, bac, bca, cba, bab all are valid. How do I write a hunspell affix file for this?
affix file:
PFX A Y 1
PFX A 0 a .
PFX B Y 1
PFX B 0 b .
PFX C Y 1
PFX C 0 c .
SFX a Y 1
SFX a 0 a .
SFX b Y 1
SFX b 0 b .
SFX c Y 1
SFX c 0 c .
This is just an example assuming there are only 3 characters (ABC) but it can be extended to A to Z.
Dict file:
a/BCbc
b/ACac
c/ABab
Is there any other better way to write this code or this is the only way to achieve this?

Finding the location of ones in a bit mask - Julia

I have a series of values that are each being stored as UInt16. Each of these numbers represents a bitmask - these numbers are commands that have been sent to a microprocessor telling it which pins to set high or low. I would like to parse this arrow of commands to find out which pins were being set high each time in such a way that is easier to analyse later.
Consider the example value 0x3c00, which in decimal is 15360 and in binary is 0011110000000000. Currently I have the following function
function read_message(hex_rep)
return findall.(x -> x .== '1',bitstring(hex_rep))
end
Which gets called on every element of the array of UInt16. Is there a better/more efficient way of doing this?
The best approach probably depends on how you want to handle vectors of hex-values. But here's an approach for processing a single hex which is much faster than the one in the OP:
function readmsg(x::UInt16)
N = count_ones(x)
inds = Vector{Int}(undef, N)
if N == 0
return inds
end
k = trailing_zeros(x)
x >>= k + 1
i = N - 1
inds[N] = n = 16 - k
while i >= 1
(x, r) = divrem(x, 0x2)
n -= 1
if r == 1
inds[i] = n
i -= 1
end
end
return inds
end
I can suggest padding your vector into a Vector{UInt64} and use that to manually construct a BitVector. The following should mostly work (even for input element types other than UInt16), but I haven't taken into account specific endianness you might want to respect:
julia> function read_messages(msgs)
bytes = reinterpret(UInt8, msgs)
N = length(bytes)
nchunks, remaining = divrem(N, sizeof(UInt64))
padded_bytes = zeros(UInt8, sizeof(UInt64) * cld(N, sizeof(UInt64)))
copyto!(padded_bytes, bytes)
b = BitVector(undef, N * 8)
b.chunks = reinterpret(UInt64, padded_bytes)
return b
end
read_messages (generic function with 1 method)
julia> msgs
2-element Vector{UInt16}:
0x3c00
0x8000
julia> read_messages(msgs)
32-element BitVector:
0
0
0
0
0
0
0
0
0
⋮
0
0
0
0
0
0
0
1
julia> read_messages(msgs) |> findall
5-element Vector{Int64}:
11
12
13
14
32
julia> bitstring.(msgs)
2-element Vector{String}:
"0011110000000000"
"1000000000000000"
(Getting rid of the unnecessary allocation of the undef bit vector would require some black magic, I belive.)

If p → q then q → p?

I'm trying to get back into boolean algebra after many years without it, I'm currently working on an exercise that asks to verify if p → q or q → p are tautologies, p and q being very long expressions hard to simplify, yet p → q is very easy to prove a tautology using a truth table while q → p takes a lot longer to verify using a truth table.
Is the statement p → q ≡ q → p correct? I can't find concise info on this proposition but building the truth table makes it seem like it is correct.
If it is I could answer that since p → q is a tautology q → p is too.
When I understand your question right, then a look at the truth-table shows the following:
a -> b = c | b -> a = c
0 -> 0 = 1 | 0 -> 0 = 1
0 -> 1 = 1 | 0 -> 1 = 0
1 -> 0 = 0 | 1 -> 0 = 1
1 -> 1 = 1 | 1 -> 1 = 1
This show that a->b is not euqal to b->a.
I hope this help a little bit.

One-dimensional Convolution Example

I'm trying to understand 1-dimensional convolution. Can someone explain--potentially step by step--how convolve(A,B) works for vectors A=[a,b,c] and B=[d,e,f]. Thanks!
I'm not sure what exacly you wan to do with this convolution, but here you can find amazing pdf about this. In first chapter there's example for 1-dimensional data. Later there are some examples and explanations form image processing.
Hope it will help you!
For the linear convolution result [v,w,x,y,z],
first reverse [d,e,f] to [f,e,d] , then input the first element of [a,b,c] :
v = f * 0 + e * 0 + d * a
for the next output, shift 0,0,a,b,c to the left by 1 and use the same f,e,d
w = f * 0 + e * a + d * b
for the next output, shift 0,a,b,c to the left by 1 and use the same f,e,d
x = f * a + e * b + d * c
for the next output, shift a,b,c to the left by 1 and use the same f,e,d
y = f * b + e * c + d * 0
for the next output, shift a,b,c to the left by 1 and use the same f,e,d
z = f * c + e * 0 + d * 0
For circular convolution replace the zeros with inputs that are wrapped around elements inside [a,b,c].