+ 1
Please help my assigment:(
How to test whether a set is reflexive, symmetric, anti symmetric and or transitive? How to test whether a function is bijective, injective and surjective? can i use array 2D?
6 Answers
+ 4
It looks like this will be more difficult than I thought. I have implemented sets and the relation set in a program, but reading an expression is the most difficult part. I guess ill just make a program to read a relation set and check from that, first.
+ 3
The reflexibility of the relation can be easily checked. All you need is the original set A and the equation of relation (like a+b%5==0). Then find pairs a,b and form a relation set. Then for all elements in A, check if a,a belongs to the relation, using a for loop.
The check of a R as symmetric is similarly checked by checking for each a,b in R, b,a is also in R. To make things easier, you may use a custom belong function.
To check for transitive you will again need a for loop and traverse through the elements.
In all cases, you need the domain and the relation equation. Note that for large domains (like R), you need algebra which will further require some library to implement.
For functions, if you have the function and the domain, you may use for loops as in Relations.
Ill try posting a code by tomorrow afternoon.
Instead of using 2d arrays, use an array of pairs, where each element can store 2 elements
+ 2
Reflexive, symmetric, anti-symmetric, transitive, bijective, injective, surjective ... Oh m'y... I'm still a first level learner and I don't know anything yet!
+ 2
https://code.sololearn.com/cF8YV2A4RqE2/?ref=app
Try this for starters. It can check if R is reflexive, symmetric or transitive.