Question

Python 3 Discrete​ ​Mathematics We are going to write a program to read in relations, show...

Python 3

Discrete​ ​Mathematics

We are going to write a program to read in relations, show the matrix of the relation. We will also show if the relation is reflexive, symmetric, anti-symmetric and transitive. This program will read in files that the user gives. Normal Error handling applies. The file the user gives you will have the elements of the set for the relation followed by the tuples in the relation.

The​ ​Text​ ​Files

The first line of the text file is all the elements in the set separated by commas. Each line thereafter should contain 2 of the elements separated by a comma.

x,y, z

x,x

y,y

z,z

x, y

Line 1 above is x, y, z. The relation is a binary relation and will be over elements x, y and z. Line 2-5 is a tuple in the relation showing the relationships { (x, x), (y, y), (z, z), (x, y) }

The lines after line 1 should only have 2 elements separated by a single comma. If it doesn’t, then it is an invalid line. Any of the elements in line 2 onward will be an element contained in the first line.

Sample​ ​Output

>>> ================================ RESTART ================================

>>> >>> ================================ RESTART ================================

>>> Enter the name of the relation file. Enter quit to exit ==> 1.txt

Relation on set {a,b}

Matrix of Relation

a b

a 0 1

b 1 0

Square of Relation

a b

a 1 0

b 0 1

The relation is not reflexive

The relation is symmetric

The relation is not anti-symmetric

The relation is not transitive

Enter the name of the relation file.

Enter quit to exit ==> nofile.txt

Could not open the file given. Please enter another file

Enter the name of the relation file. Enter quit to exit ==> 2.txt

Relation on set {x,y,z}

Matrix of Relation

x y z

x 1 0 0

y 0 1 0

z 0 0 1

Square of Relation

x y z

x 1 0 0

y 0 1 0

z 0 0 1

The relation is reflexive

The relation is symmetric

The relation is anti-symmetric

The relation is transitive

Enter the name of the relation file. Enter quit to exit ==> 3.txt

Relation on set {a,b,c,d,e}

Matrix of Relation

a b c d e

a 1 1 1 0 0

b 0 1 1 0 0

c 0 0 1 0 0

d 0 0 0 1 1

e 0 0 0 0 1

Square of Relation

a b c d e

a 1 2 3 0 0

b 0 1 2 0 0

c 0 0 1 0 0

d 0 0 0 1 2

e 0 0 0 0 1

The relation is reflexive

The relation is not symmetric

The relation is anti-symmetric

The relation is not transitive

Enter the name of the relation file. Enter quit to exit ==> 4.txt

Relation on set {s,t,u,v,w}

Matrix of Relation

s t u v w

s1 1 0 0 0

t 1 1 0 0 0

u 0 0 1 1 1

v 0 0 1 1 1

w 0 0 1 1 1

Square of Relation

s t u v w

s 2 2 0 0 0

t 2 2 0 0 0

u 0 0 3 3 3

v 0 0 3 3 3

w 0 0 3 3 3

The relation is reflexive

The relation is symmetric

The relation is not anti-symmetric

The relation is transitive

Enter the name of the relation file. Enter quit to exit ==> 5.txt

Could not open the file given. Please enter another file

Enter the name of the relation file. Enter quit to exit ==> bad_file.txt

There must be 2 elements for an edge a, b, c

Could not find element x specified in line x, a

Could not find element y specified in line b, y

Relation on set {a,b,c,d}

Matrix of Relation

a b c d

a 0 0 0 0

b 0 0 0 0

c 0 0 0 0

d 0 0 0 0

Square of Relation

a b c d

a 0 0 0 0

b 0 0 0 0

c 0 0 0 0

d 0 0 0 0

The relation is not reflexive

The relation is symmetric

The relation is anti-symmetric

The relation is transitive

Enter the name of the relation file. Enter quit to exit ==> quit

>>>

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Python 3 Discrete​ ​Mathematics We are going to write a program to read in relations, show...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Show your work, please 3. Relations - No Proofs! Determine (no proof needed!) whether each of...

    Show your work, please 3. Relations - No Proofs! Determine (no proof needed!) whether each of the following relations R, S, T on the set of real numbers is reflexive, symmetric, antisymmet- ric, and/or transitive. a) x Ry iff 3 - y is positive: reflexive: symmetric: anti-symmetric: transitive: b) xSy iff 2 = 2y: reflexive: symmetric anti-symmetric: transitive: c) Ty iff zy 30: reflexive: symmetric: anti-symmetric transitive:

  • Show work/explain please! 1. (15) Characterize the following relations in terms of whether they are reflexive,...

    Show work/explain please! 1. (15) Characterize the following relations in terms of whether they are reflexive, irreflexive, symmetric, anti- symmetric, transitive, complete, any sort of ordering relation, and/or an equivalence relation. a. R CRX R with R = {(x,y)|x<y>} b. RCRXR with R= {(x, y)|x3 = y3} C. RSRXR with R = {(x, y) x2 + y2}

  • 4. Give the directed graph of a relation on the set ( x,y,z that is a)...

    4. Give the directed graph of a relation on the set ( x,y,z that is a) not reflexive, not symmetric, but transitive b) irreflexive, symmetric, and transitive c) neither reflexive, irreflexive, symmetric, antisymmetric, nor transitive d) a poset but not a total order e) a poset and a total order

  • 3. (12 pts) Determine whether the following binary relation is: (1) reflexive, (2) symmetric, (3) antisymmetric,...

    3. (12 pts) Determine whether the following binary relation is: (1) reflexive, (2) symmetric, (3) antisymmetric, (4) transitive. a) The relation Ron Z where aRb means a = b. Circle your answers. (4 pts) Ris Reflexive? Symmetric? Antisymmetric? Transitive? Yes or No Yes or No Yes or No Yes or No b) The relation R on the set of all people where aRb means that a is taller than b. Circle your answers. (4 pts) Ris Reflexive? Symmetric? Antisymmetric? Transitive?...

  • QI. Let A-(-4-3-2-1,0,1,2,3,4]. R İs defined on A as follows: For all (m, n) E A,...

    QI. Let A-(-4-3-2-1,0,1,2,3,4]. R İs defined on A as follows: For all (m, n) E A, mRn㈠4](rn2_n2) Show that the relation R is an equivalence relation on the set A by drawing the graph of relation Find the distinct equivalence classes of R. Q2. Find examples of relations with the following properties a) Reflexive, but not symmetric and not transitive. b) Symmetric, but not reflexive and not transitive. c) Transitive, but not reflexive and not symmetric. d) Reflexive and symmetric,...

  • Thank You. 3. For each of the relations below, draw their graph, and say which of...

    Thank You. 3. For each of the relations below, draw their graph, and say which of the following properties they satisfy. Answer this question using the following sets. A = {0,1,2), B = {0}, D = P({0,1)) a. R= {(x,y) E AXA X Sy?) List of properties satisfied: b. R = {(x,y) EB X Bl x*y> 4} List of properties satisfied: Properties • Reflexive Anti-reflexive • Symmetric Anti-Symmetric Transitive Partial Order Total • Equivalence c. R= {(x,y) EDx D x...

  • Given the following binary relations: The relation Rl on {w, 1, y, z), where R1 =...

    Given the following binary relations: The relation Rl on {w, 1, y, z), where R1 = {(w, w), (w, 1), (x, w), (x, 1 ), (x, z), (y, y), (z,y),(2, 2)). The relation R2 on (a, b, c), where R2 = {(a, a ), (b, b), (c, c), (a, b), (a, c), (c, b)}. The relation R3 on {x,y,z}, where R3 = {(1, 2), (9,2), (2, y)}. Determine whether these relations are: (1) reflexive, (2) symmetric, (3) antisymmetric, (4) transitive?

  • For each of the following relations on the set of all real numbers, decide whether or...

    For each of the following relations on the set of all real numbers, decide whether or not the relation is reflexive, symmetric, antisymmetric, and/or transitive. Give a brief explanation of why the given relation either has or does not have each of the properties. (x, y) elementof R if and only if: a. x + y = 0 b. x - y is a rational number (a rational number is a number that can be expressed in the form a/b...

  • Question 2 For each of the following relations R, determine (and explain) whether R is: (1) reflexive (2) symmetric (3) antisymmetric (4) transitive (a) R-(x, y):x +2y 3), defined on the set A 10...

    Question 2 For each of the following relations R, determine (and explain) whether R is: (1) reflexive (2) symmetric (3) antisymmetric (4) transitive (a) R-(x, y):x +2y 3), defined on the set A 10, 1,2,3) (b) R-I(x, y): xy 4), defined on the set A (0,1,2,3,4 (c) R-(x, y): xy 4), defined on the set A-0,,2,3) Question 2 For each of the following relations R, determine (and explain) whether R is: (1) reflexive (2) symmetric (3) antisymmetric (4) transitive (a)...

  • 10. For each of the following relations on the set of all real numbers, determine whether...

    10. For each of the following relations on the set of all real numbers, determine whether it is reflexive, symmetric, antisymmetric, transitive. Here rRy if and only if: (b)-2y (d) ry -0 (f) x-1 or y 1 (h) ry-1 (a) x+ 2y-0 ( C)-y is a rational number (e) xy20 (g) z is a multiple of y

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT