I'm trying to determine whether or not sets of tuples have a certain type of relation. I'm trying to figure out the transitive relation, and the composite relation.
For the transitive relation:
For example:
For the composite relation:
For example:
I am uncertain on how to start coding these functions. Any help to get me started would be greatly appreciated. Thank you!
EDIT:Here are some other relations I was able to successfully code:
Is It Transitive Calculator Free
Coder117
Coder117Coder117
2 Answers
For the transitive test, just convert the math definition in Python:
Serge BallestaSerge Ballesta87.4k99 gold badges6565 silver badges143143 bronze badges
I believe this is a brute force approach that works. First, we are going to use an 'adjacency set' representation, then just test explicitly using a deeply nested for-loop:
However, for your second example:
Using this data structure should make it a little less horrible from a time-complexity POV.
As for constructing the composite:
Or, just sticking with sets of tuple:
juanpa.arrivillagajuanpa.arrivillaga40.7k33 gold badges4242 silver badges7878 bronze badges
Not the answer you're looking for? Browse other questions tagged pythonsettuplesrelation or ask your own question.
Prerequisite : Introduction to Relations, Representation of Relations
Combining Relations :
As we know that relations are just sets of ordered pairs, so all set operations apply to them as well. Two relations can be combined in several ways such as –
- Union – consists of all ordered pairs from both relations. Duplicate ordered pairs removed from Union.
- Intersection – consists of ordered pairs which are in both relations.
- Difference – consists of all ordered pairs only in , but not in .
- Symmetric Difference – consists of all ordered pairs which are either in or but not both.
Is It Transitive Calculator Worksheet
![Transitive Transitive](https://images.tutorvista.com/cms/images/69/banner.jpg)
![Is It Transitive Calculator Is It Transitive Calculator](https://www.dummies.com/wp-content/uploads/220469.image3.jpg)
There is another way two relations can be combined that is analogous to the composition of functions.
Composition – Let be a relation from to and be a relation from to , then the composite of and , denoted by , is the relation consisting of ordered pairs where and for which there exists an element such that and .
- Example – What is the composite of the relations and where is a relation from to with and is a relation from to with ?
- Solution – By computing all ordered pairs where the first element belongs to and the second element belongs to , we get –
Composition of Relation on itself :
A relation can be composed with itself to obtain a degree of separation between the elements of the set on which is defined.
Theorem – Let be a relation on set A, represented by a di-graph. There is a path of length , where is a positive integer, from to if and only if .
Important Note : A relation on set is transitive if and only if for
Closure of Relations : Game consoles for sale in south africa.
Consider a relation on set . may or may not have a property , such as reflexivity, symmetry, or transitivity.
If there is a relation with property containing such that is the subset
of every relation with property containing , then is called the closure of
with respect to .
of every relation with property containing , then is called the closure of
with respect to .
We can obtain closures of relations with respect to property in the following ways –
- Reflexive Closure – is the diagonal relation on set . The reflexive closure of relation on set is .
- Symmetric Closure – Let be a relation on set , and let be the inverse of . The symmetric closure of relation on set is .
- Transitive Closure – Let be a relation on set . The connectivity relation is defined as – . The transitive closure of is .
![Transitive Transitive](/uploads/1/2/3/7/123760102/432585521.png)
Example – Let be a relation on set with . Find the reflexive, symmetric, and transitive closure of R.
Solution –
For the given set, . So the reflexive closure of is
For the given set, . So the reflexive closure of is
For the symmetric closure we need the inverse of , which is
.
The symmetric closure of is-
.
The symmetric closure of is-
For the transitive closure, we need to find .
we need to find until . We stop when this condition is achieved since finding higher powers of would be the same.
Since, we stop the process.
Transitive closure, –
we need to find until . We stop when this condition is achieved since finding higher powers of would be the same.
Since, we stop the process.
Transitive closure, –
Equivalence Relations :
Let be a relation on set . If is reflexive, symmetric, and transitive then it is said to be a equivalence relation.
Consequently, two elements and related by an equivalence relation are said to be equivalent.
Consequently, two elements and related by an equivalence relation are said to be equivalent.
Example – Show that the relation
is an equivalence relation. is the congruence modulo function. It is true if and only if divides .
is an equivalence relation. is the congruence modulo function. It is true if and only if divides .
Solution – To show that the relation is an equivalence relation we must prove that the relation is reflexive, symmetric and transitive.
- Reflexive – For any element , is divisible by .
. So, congruence modulo is reflexive. - Symmetric – For any two elements and , if or i.e. is divisible by , then is also divisible by .
. So Congruence Modulo is symmetric. - Transitive – For any three elements , , and if then-
Adding both equations,. So, is transitive. - Example : What are the equivalence classes of the relation Congruence Modulo ?
- Solution : Let and be two numbers such that . This means that the remainder obtained by dividing and with is the same.
Possible values for the remainder-
Therefore, there are equivalence classes –
Since the relation is reflexive, symmetric, and transitive, we conclude that is an equivalence relation.
Equivalence Classes :
Let be an equivalence relation on set .
We know that if then and are said to be equivalent with respect to .
We know that if then and are said to be equivalent with respect to .
The set of all elements that are related to an element of is called the
equivalence class of . It is denoted by or simply if there is only one
relation to consider.
Formally,
equivalence class of . It is denoted by or simply if there is only one
relation to consider.
Formally,
Any element is said to be the representative of .
Important Note : All the equivalence classes of a Relation on set are either equal or disjoint and their union gives the set .
The equivalence classes are also called partitions since they are disjoint and their union gives the set on which the relation is defined
Important Note : All the equivalence classes of a Relation on set are either equal or disjoint and their union gives the set .
The equivalence classes are also called partitions since they are disjoint and their union gives the set on which the relation is defined
GATE CS Corner Questions
Practicing the following questions will help you test your knowledge. All questions have been asked in GATE in previous years or in GATE Mock Tests. It is highly recommended that you practice them.
1. GATE CS 2013, Question 1
2. GATE CS 2005, Question 42
3. GATE CS 2001, Question 2
4. GATE CS 2000, Question 28
2. GATE CS 2005, Question 42
3. GATE CS 2001, Question 2
4. GATE CS 2000, Question 28
References –
Composition of Relations – Wikipedia
Discrete Mathematics and its Applications, by Kenneth H Rosen
Composition of Relations – Wikipedia
Discrete Mathematics and its Applications, by Kenneth H Rosen
This article is contributed by Chirag Manwani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.