0% found this document useful (0 votes)
12 views11 pages

Class - Practical 1to3

Uploaded by

dbbhatla00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

Class - Practical 1to3

Uploaded by

dbbhatla00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

PRACTICAL-1

Relations as Ordered Pairs


To check if the entered data is an ordered pair or not
pairQ@8_, _<D := True;
pairQ@___D := False
pairQ@85, "b"<D
True
pairQ@82, 3<D
True

pairQ@5D
False
pairQ@85, 6, 7<D
False
pairQ@2, 3D
False
pairQ@D
False
2 Class_practical 1to3 - Copy.nb

pairQ@8, <D
True

To check if the entered data is a relation or not


relationQ@8___ ? pairQ<D := True;
relationQ@___D := False
* a relation must be a list
containing a BlankNullSequence H___ L, i.e.,
a comma - separated sequence of expressions,
each one of which satisfies pairQ. *
Tuples@81, 2, 3<, 2D
881, 1<, 81, 2<, 81, 3<, 82, 1<, 82, 2<, 82, 3<, 83, 1<, 83, 2<, 83, 3<<
dividesRelation@A : 8__Integer<D :=
Select@Tuples@A, 2D, Divisible@ð@@2DD, ð@@1DDD &D
*To the output of Tuples, we apply Select to obtain the sublist of ele-
ments that satisfy the divisibility condition. Select requires two argu-
ments. The first is the list of elements to select from. The second is a
function name or a pure Function (&) that returns True for the desired
elements. *
dividesRelation@Range@4DD
881, 1<, 81, 2<, 81, 3<, 81, 4<, 82, 2<, 82, 4<, 83, 3<, 84, 4<<
*to construct the divides relation on the integers 1 through 4.*
relationQ@%D
True
dividesRelation@n_IntegerD :=
Select@Tuples@Range@nD, 2D, Divisible@ð@@2DD, ð@@1DDD &D
Class_practical 1to3 - Copy.nb 3

div6 = dividesRelation@6D
881, 1<, 81, 2<, 81, 3<, 81, 4<, 81, 5<, 81, 6<, 82, 2<,
82, 4<, 82, 6<, 83, 3<, 83, 6<, 84, 4<, 85, 5<, 86, 6<<

Reverse@81, 2, 3<D
83, 2, 1<
The Inverse of a Relation
inverseRelation@R_ ? relationQD := Reverse@R, 2D
mul6 = inverseRelation@div6D
881, 1<, 82, 1<, 83, 1<, 84, 1<, 85, 1<, 86, 1<, 82, 2<,
84, 2<, 86, 2<, 83, 3<, 86, 3<, 84, 4<, 85, 5<, 86, 6<<
Reverse accepts a second optional argument to specify a level. In this
case we use 2 to indicate that we want Reverse to change the order of
the sublists of the relation, not the order of the elements of R itself.

PRACTICAL 2
Finding whether or not, a given relation is Reflexive/ Antisymetric/-
Transitive/Partial Order.
We will first extract the domain of a given relation by applying Flatten
to the relation.
subsets1 = 888<, 81<<, 88<, 82<<, 88<, 81, 2<<,
881<, 81, 2<<, 882<, 81, 2<<, 881, 2<, 81, 2<<<;
4 Class_practical 1to3 - Copy.nb

Flatten@subsets1, 1D
88<, 81<, 8<, 82<, 8<, 81, 2<, 81<, 81, 2<, 82<, 81, 2<, 81, 2<, 81, 2<<
After flattening, we apply Union to remove duplicates and put the out-
put in canonical order.
findDomain@R_ ? relationQD := Union@Flatten@R, 1DD
findDomain@div6D
81, 2, 3, 4, 5, 6<
findDomain@subsets1D
88<, 81<, 82<, 81, 2<<

To check if a relation is reflexive or not


A relation R is reflexive if Ha, aL Î R for every a in the domain.
reflexiveQ@R_ ? relationQD := Module@8a, domain<,
domain = findDomain@RD;
Catch@
Do@If@! MemberQ@R, 8a, a<D, Throw@FalseDD
, 8a, domain<D;
Throw@TrueD
D
D
Class_practical 1to3 - Copy.nb 5

reflexiveQ@div6D
True

To check if a relation is antisymmetric or not


To determine whether a given relation R is antisymmetric or not. A
relation is antisymmetric when it has the property that whenever a
pair Ha, bL and its reverse Hb, aL both belong to R, then it must be that
a = b. To check this, we simply loop over all members u of R and see if
the opposite pair belongs to R and whether the members of the pair are
different.
antisymmetricQ@R_ ? relationQD := Module@8u<,
Catch@
Do@If@MemberQ@R, Reverse@uDD && u@@1DD ¹ u@@2DD,
Throw@FalseDD
, 8u, R<D;
Throw@TrueD
D
D
antisymmetricQ@div6D
True
6 Class_practical 1to3 - Copy.nb

antisymmetricQ@mul6D
True

To check if a relation is transitive or not

To check transitivity, we will consider all possible a, b, and c in the


domain of R. Then if Ha, bL Î R, Hb, cL Î R, and Ha, cL Ï R, we know
that the relation is not transitive. If there is no such triple a, b, c to
contradict transitivity, then we conclude that the relation is transitive.
transitiveQ@R_ ? relationQD := Module@8domain, a, b, c<,
domain = findDomain@RD;
Catch@
Do@If@MemberQ@R, 8a, b<D && MemberQ@R, 8b, c<D &&
! MemberQ@R, 8a, c<D, Throw@FalseDD
, 8a, domain<, 8b, domain<, 8c, domain<D;
Throw@TrueD
D
D
transitiveQ@div6D
True

To check if a relation is partial order or not


partialOrderQ@R_ ? relationQD :=
reflexiveQ@RD && antisymmetricQ@RD && transitiveQ@RD
Class_practical 1to3 - Copy.nb 7

partialOrderQ@div6D
True

PRACTICAL - 3
Finding the following for a given partially ord-
ered set:
i) Covering relations
ii) The corresponding Hasse diagram representa-
tion
iii) Minimal and maximal elements
*Let b be a partial order on a set S. Recall that an element y in S covers
an element x in S if x< y , x ¹ y,
and there is no element z of S, different from x and y, such that x < z < y.
The set of pairs (x, y) for which y covers x is the covering relation of b .*
coversQ@R_ ? partialOrderQ, 8x_, y_<D :=
Module@8z, checkSet<,
Catch@
If@x Š y, Throw@FalseDD;
If@! MemberQ@R, 8x, y<D, Throw@FalseDD;
checkSet = Complement@findDomain@RD, 8x, y<D;
Do@If@MemberQ@R, 8x, z<D &&
MemberQ@R, 8z, y<D, Throw@FalseDD
, 8z, checkSet<D;
Throw@TrueD
D
D
This function works by first checking to see if the two elements x and y
are equal to each other or if the pair Hx, yL fails to be in the partial order.
In either of these situations, y does not cover x. Assuming the pair of
elements passes these basic hurdles, the function then checks every other
element of the domain. If it can find an element that sits between x and
8 Class_practical 1to3 - Copy.nb

This function works by first checking to see if the two elements x and y
are equal to each other or if the pair Hx, yL fails to be in the partial order.
In either of these situations, y does not cover x. Assuming the pair of
elements passes these basic hurdles, the function then checks every other
element of the domain. If it can find an element that sits between x and
y, then we know they don't cover. If no element sits between them, then
in fact y does cover x.
coveringRelation@R_ ? partialOrderQD :=
Select@R, coversQ@R, ðD &D
coveringRelation@881, 1<, 81, 2<, 81, 3<, 81, 4<,
82, 2<, 82, 3<, 82, 4<, 83, 3<, 83, 4<, 84, 4<<D
881, 2<, 82, 3<, 83, 4<<
divisorLattice@n_IntegerD :=
dividesRelation@Divisors@nDD
divisorLattice@10D
881, 1<, 81, 2<, 81, 5<, 81, 10<,
82, 2<, 82, 10<, 85, 5<, 85, 10<, 810, 10<<
coveringRelation@divisorLattice@10DD
881, 2<, 81, 5<, 82, 10<, 85, 10<<
Class_practical 1to3 - Copy.nb 9

coveringRelation@divisorLattice@6DD
881, 2<, 81, 3<, 82, 6<, 83, 6<<

Drawing Hasse Diagrams


hasseDiagram@R_ ? partialOrderQD :=
Module@8edges<,
edges = coveringRelation@RD .
8a_, b_< ® Rule@b, aD;
LayeredGraphPlot@edges, VertexLabeling ® TrueD
D
hasseDiagram@divisorLattice@30DD

30

6 10 15

2 3 5

1
10 Class_practical 1to3 - Copy.nb

hasseDiagram@divisorLattice@210DD

210

30 42 70 105

6 10 14 15 21 35

2 3 5 7

Maximal and Minimal Elements


minimalElements@R_ ? partialOrderQ, S_ListD :=
Module@8M, s, t<,
M = S;
Do@
Do@
If@MemberQ@R, 8t, s<D, M = Complement@M, 8s<DD
, 8t, Complement@S, 8s<D<D
, 8s, S<D;
M
D
Class_practical 1to3 - Copy.nb 11

hasseDiagram@div6D

4 6

5 2 3

minimalElements@div6, Range@6DD
81<
minimalElements@div6, Range@2, 6DD
82, 3, 5<
maximalElements@R_ ? partialOrderQ, S_ListD :=
minimalElements@inverseRelation@RD, SD
maximalElements@div6, Range@6DD
84, 5, 6<

You might also like