Question: 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

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 doesnt, 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

>>>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!