R o R (Discrete Mathematics - Relations on Sets) - set

The following is given
Let A = {1, 2, 3, 4}
Let R = the relation on the set A, or:
R = {(1,1), (1,2), (1,3), (2,1), (3,2), (3,3), (4,4)}
Find R o R as a set of tuples.
I am not certain how to approach this problem.
My best guess is
R o R = {((1,1),(1,1)), ((1,1),(1,2), ..., ((4,4),(4,4))}
but that does not seem right to me. I'm looking for how to solve this type of problem, not just a solution to this problem.
Any help would be appreciated!

According to Definition 6 from Chapter 8:Relations and Thier Properties :
S ○ R
Composite relation of R and S where
R from A to B
S from B to C
is the ordered pairs:
(a, c), where a ∈ A and c ∈ C
for which b ∈ B such that
(a, b) ∈ R ^ (b, c) ∈ S
(a, c) ∈ S ○ R if (a, b) ∈ R ^ (b, c) ∈ S
and using example that follows it, one can get
So the final answer is
R ○ R = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2), (3,3), (4,4)}

Related

What are the inorder and postorder traversals of the following tree?

With respect to the following tree:
What is the correct inorder traversal?
U S T X C P Y R B A I G J F N H V T E D L
U S T X C P Y R B A D E I G J F N H V T L
What is the correct postorder traversal?
U T S X P R Y C B D I J G N V T H F E L A
U T S X P R Y C B I J G N V T H F E D L A
I evaluated both pairs. But some are saying 1-1 and 2-1 are correct, while others say 1-2 and 2-2 are correct. I'm confused. Which ones are actually correct?
inorder:
B U S T X C P Y R A D E I G J F N H V T L
postorder (2.2 is correct):
U T S X P R Y C B I J G N V T H F E D L A

How to multiply Column vector by Row vector in Mathematica?

I want to multiply every value in a column vector by the same vector but transposed to row. The output should be a multiplication table matrix. Like the third example in this picture.
I tried multiplying a column vector by its transposed form but Mathematica only gives me this which is not a Matrix.
Bryan,
You need to use Dot, not Times. See docs.
m = {{a}, {b}, {c}}
m.Transpose[m]
{{a^2, a b, a c}, {a b, b^2, b c}, {a c, b c, c^2}}
You might inappropriately define row vectors and column vectors. Try this:
rowvec={{a,b,c}};
colvec={{d},{e},{f}};
Then the command dot will give both inner product and outer product correctly.
rowvec.colvec
output: {{a d + b e + c f}}
colvec.rowvec
output: {{a d, b d, c d}, {a e, b e, c e}, {a f, b f, c f}}

Exponents are not getting add

I am a beginner in Mathematica and learning from Google.
I was trying to find the determinant of a 4*4 matrix.
TT = {{ap, b, c, d}, {e, fp, g, h}, {i, j, kp, l}, {m, n, o, pq}}
TT // MatrixForm
After it, I applied determinant command.
Det[TT]
I am getting result as follow,
d g j m - c h j m - d fp kp m + b h kp m + c fp l m - b g l m - d g i n + c h i n + d e kp n - ap h kp n - c e l n + ap g l n + d fp i o - b h i o - d e j o + ap h j o + b e l o - ap fp l o - c fp i pq + b g i pq + c e j pq - ap g j pq - b e kp pq + ap fp kp pq
I want above expression as a polynomial in p, want to collect coefficients separately. I have tried various command such as Collect, Factor etc. But each time I get the answer as the same polynomial as above.
I assume you have a*p, f*p, k*p, p*q, instead of ap, fp, kp and pq.
Mathematica needs either space or multiple sign to treat them as a separate multiplier and not as a variable.
t = {{a p, b, c, d}, {e, f p, g, h}, {i, j, k p, l}, {m, n, o,
p q}};
Collect[Det[t], p]
(* d g j m - c h j m - b g l m - d g i n + c h i n - c e l n -
b h i o - d e j o + b e l o + a f k p^4 q +
p (b h k m + c f l m + d e k n + a g l n + d f i o + a h j o +
b g i q + c e j q) +
p^2 (-d f k m - a h k n - a f l o - c f i q - a g j q - b e k q) *)

How sorting list of string by length

Hi i having a problem with sort list like:
sort([p v q v r, p, p v q], R).
expected result is
R = [p, p v q, p v q v r]
Is any built in sort in swi-prolog which allow me that or i have to write it myself.

Generating First Set from the grammar

Algorithm for Finding first set:
Given a grammar with the rules A1 → w1, ..., An → wn, we can compute the Fi(wi) and Fi(Ai) for every rule as follows:
initialize every Fi(Ai) with the empty set
set Fi(wi) to Fi(wi) for every rule Ai → wi, where Fi is defined as follows:
Fi(a w' ) = { a } for every terminal a
Fi(A w' ) = Fi(A) for every nonterminal A with ε not in Fi(A)
Fi(A w' ) = Fi(A) \ { ε } ∪ Fi(w' ) for every nonterminal A with ε in Fi(A)
Fi(ε) = { ε }
add Fi(wi) to Fi(Ai) for every rule Ai → wi
do steps 2 and 3 until all Fi sets stay the same.
Grammar:
A -> B C c
A -> g D B
B -> EPSILON | b C D E
C -> D a B | c a
D -> EPSILON | d D
E -> g A f | c
This website generates the first set as follows:
Non-Terminal Symbol First Set
A g, ε, b, a, c, d
B ε, b
C a, c, ε, d
D ε, d
E g, c
But the algorithm says Fi(A w' ) = Fi(A) for every nonterminal A with ε not in Fi(A) so the First(A) according to this algorithm should not contain ε. First(A) = {g, b, a, c, d}.
Q: First(A) for the above grammar is = First(B) - ε U First(C) U {g} ?
This video also follows the above algorithm and do not choose ε.
First(B) = {ε, b}
First(D) = {ε, d}
First(E) = {g, c}
First(C) = {c, d, a}
First(A) = {b, g, c, d, a}
Example:
X -> Y a | b
Y -> c | ε
First(X) = {c, a, b}
First(Y) = {c, ε}
First(X) doesn't have ε because if you replace Y by ε, then First(Y a) is equal to First(ε a) = {a}
First set implementation on my github.
Edit: Updated link
https://github.com/amirbawab/EasyCC-CPP/blob/master/src/syntax/grammar/Grammar.cpp#L229
Computing the first and follow sets are both available on the new link above.

Resources