I need to simplify this expression. I know the answer must be (Not A or Not C) but I keep getting C or (Not A and C)
Tried this in Lua:
local a = false
local b = true
local c = true
local f = (not b and not c) or (b and not c) or (not a and c)
local f_= not c or (not a and c)
print(f, f_)
Output: false, false
I also tried all the possibilities with all three variables and both 'f' and 'f_' remained identical.
F = (Not B and Not C) or (B and Not C) or (Not A and C)
-> (Not B and Not C) or (B and Not C) == Not C
F = Not C or (Not A and C)
I like using Karnaugh maps for boolean simplification:
https://en.wikipedia.org/wiki/Karnaugh_map
For your example, we build a 2D truth table:
Then fill in the terms from your question, they all get 'or'd together:
Then you find the smallest number of squares/rectangles that cover the needed parts. The squares and rectangles must have powers of two as a dimension, so 2x2 is ok, 1x4 etc, but not 3x2 for example. These are called 'minterms' and the bigger the square, the simpler the boolean expression they represent. In the example below, the minterm for 'not C' wraps off one end of the map and on to the other, but is still considered a 2x2 square.
You can also do it by covering the unused space with 'maxterms', and then invert it again to get the original expression:
The results of 'not A or not C' and 'not (A and C)' are equivalent by De Morgan's laws. (https://en.wikipedia.org/wiki/De_Morgan%27s_laws)
(Not B and Not C) or (B and Not C) or (Not A and C)
|
| Distributive Law
V
((Not B or B) and Not C) or (Not A and C)
|
| Complement Law
V
Not C or (Not A and C)
|
| Absorption Law
V
Not C or Not A
i'm new trying to read this type of documentation, and i'm confused in how the instruction of VCDIFF works, this is the original doc:
https://www.rfc-editor.org/rfc/rfc3284
This part:
ADD: This instruction has two arguments, a size x and a sequence
of x bytes to be copied.
COPY: This instruction has two arguments, a size x and an address
p in the string U. The arguments specify the substring of U
that must be copied. We shall assert that such a substring
must be entirely contained in either S or T.
RUN: This instruction has two arguments, a size x and a byte b,
that will be repeated x times.
Now the doc put an example:
a b c d e f g h i j k l m n o p
a b c d w x y z e f g h e f g h e f g h e f g h z z z z
COPY 4, 0
ADD 4, w x y z
COPY 4, 4
COPY 12, 24
RUN 4, z
I don't understand what every op did, i think the first copy is the first "a b c d", the add now includes "w x y z", now i don't understand well how the next two copies works.
If i think would be useful if someone can show what do that instructions, like "this instruction have this string as result and the next this", just to can compare step by step :D
Thx.
It looks like at the point you are executing this you will know the length of the output. In this "language" the input and output are consecutive in "memory". So you start with:
abcdefghijklmnop----------------------------
|<- S ->||<- T ->|
First COPY 4 bytes starting at offset 0 in the combined string:
ABCDefghijklmnopABCD------------------------
|<- S ->||<- T ->|
Then ADD 4 bytes, literally w x y z:
abcdefghijklmnopabcdWXYZ--------------------
|<- S ->||<- T ->|
Then COPY 4 bytes starting at offset 4:
abcdEFGHijklmnopabcdwxyzEFGH----------------
|<- S ->||<- T ->|
Then COPY 12 bytes starting at offset 24. This is a little tricky, because offset 24 is the "efgh" we just wrote and we haven't written the last 8 bytes yet, but if you do it one byte at a time the overlap doesn't matter:
|<- from ->|
|<- to ->|
abcdEFGHijklmnopabcdwxyzefghEFGHEFGHEFGH----
|<- S ->||<- T ->|
Finally there is a RUN of 4 consecutive bytes all "z":
abcdEFGHijklmnopabcdwxyzefghefghefghefghZZZZ
|<- S ->||<- T ->|
I do understand depth and breadth first search but this graph got me confused as there is nodes that points to preceding nodes in the graph.
So let's say for instant that N is a goal state, then using Depth first search we would have
A B E J K L F G M N
So we is it correct this way ? I don't repeat the A because it was visited before right.
And using breadth first search I would go level by level and so I would have
A B C D E F G H I J K L M N
Is this correct ?
And if we change the Goal state to P
then DFS will give us A B E J K L F G M N H O P
and BFS will give us A B C D E F G H I J K L M N O P
I feel I got this right, I am just uncertain if I am right because of the returning edges in this graph. So I just want someone to confirm that I am on the right track here.
That sounds correct to me. When pointing to a node that's already in your result set, it should not be added into the result set a second time.
I want to ask about my multiple choice program that I made. I confuse how to store a value continuously, so I can take a conclusion in the end of program, based on sum of the value that already store.
start :- program.
program :-
write('This is question number 1'),nl,
write('A'),nl,
write('B'),nl,
write('C'),nl,
read(Choice),nl,
(
%case1
Choice='a'->nl,
=================================
A = A + 1 <--- Right Here,
And then go to Question 2.
=================================
%case2
Choice='b'->nl,
=================================
B = B + 1 <--- Right Here,
And then go to Question 2.
=================================
%case3
Choice='c'->nl,
=================================
C = C + 1 <--- Right Here,
And then go to Question 2.
=================================
%case_default
write('Wrong Code')
).
So I can take a conclusion like this,
===================================
if B < A > C then you're an A.
if A < B > C then you're a B.
if A < C > B then you're a C.
===================================
Thanks you very much before :)
There are many possible ways to store values. What you probably think of - storing some counters and updating them on given answers - can lead to some complicated situations. Example of code working with counters:
question('Choose a, b or c: ').
question('Choose again a, b or c: ').
question('Think before you choose a, b, or c: ').
ask :-
findall(Q, question(Q), Questions),
ask_and_count([0,0,0], [A,B,C], Questions),
max_list([A,B,C], Max),
nth1(Index,[A,B,C],Max),
nth1(Index,[a,b,c],Answer),
print('You''re a(n) '), print(Answer), nl.
ask_and_count(Count, Count, []) :-
print('Thank you, that''s all questions!'), nl, !.
ask_and_count(InCount, OutCount, [Q | Questions]) :-
print(Q),
read_abc(Ans),
increase(Ans, InCount, NewCount),
ask_and_count(NewCount, OutCount, Questions).
read_abc(A) :-
read(A),
member(A, [a,b,c]),
!.
read_abc(A) :-
print('Only a, b and c are accepted! Answer again: '),
read_abc(A).
increase(a, [A, B, C], [X, B, C]) :- X is A + 1.
increase(b, [A, B, C], [A, X, C]) :- X is B + 1.
increase(c, [A, B, C], [A, B, X]) :- X is C + 1.
Sample input and output:
?- ask.
Choose a, b or c: b.
Choose again a, b or c: c.
Think before you choose a, b, or c: c.
Thank you, that's all questions!
You're a(n) c
Maybe I can inspire you to do it another way, which in my opinion is more "prologish" as it relies on lists and leads to simpler code:
question('Choose a, b or c: ').
question('Choose again a, b or c: ').
question('Think before you choose a, b, or c: ').
read_abc(A, Choices) :-
read(A),
member(A, Choices),
!.
read_abc(A, Choices) :-
print('Only '), print(Choices), print(' are accepted! Try again: '),
read_abc(A, Choices).
ask(Answers) :-
findall(Ans, (question(Q), print(Q), read_abc(Ans, [a,b,c])), Answers).
start :-
ask(Answers),
print(Answers).
Sample input and output:
?- start.
Choose a, b or c: c.
Choose again a, b or c: b.
Think before you choose a, b, or c: c.
[c,b,c]
true.
After you have all answers in a list, you can simply count occurences of every answer.
Other way of storing choices is by using assert and retract predicates. Expert systems do that. When using assert and retract you can use some predicates like global variables known from other programming languages.
I have a 4X6 matrix split as two 2X6 matrices on 2 processors. Since the rows have been split in a contiguous way (C Language) on the processors, we can carry out a 1-D FFT on the rows. The problem is we need an MPI_Alltoall() to collect contiguous columns on a particular processor for 1-D column FFT i.e. Processor 0 has:
A B C D E F
G H I J K L
Processor 1 has:
M N O P Q R
S T U V W X
The MPI_Alltoall() needs to convert this to the following on Processor 0:
A G M S
B H N T
C I O U
And the following on Processor 2:
D J P V
E K Q W
F L R X
I tried to define a vector having count=2, blocklength=1, stride=6 as the sending type vector, set its extent to MPI_INT, displacement to 0 and sent 3 instances of this vector using MPI_Alltoall(). This according to me should send A G, B H, and C I to processor 0 and D J, E K, and F L to processor 1. Similarly M S, N T, and O U to processor 0 and P V, Q W, and R X to processor 1.
Is my interpretation correct ? If yes, then how do I receive these 3 instances of vectors on the receiving side ( What/How do I define the datatype?).