Class - Practical 1to3
Class - Practical 1to3
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
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<<
reflexiveQ@div6D
True
antisymmetricQ@mul6D
True
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<<
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
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<