Test 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Name : Raushan Kumar

RollNo: 23/17104
In[1]:= pairQ[{_ , _}] := True;
pairQ_ _ _ := False;

In[3]:= relationQ___ ? relationQ := True;


relationQ[___] := False;

In[7]:= dividesRelation[A _ : {_Integer}] := Select[Tuples[A, 2], Divisible[#〚2〛, #〚1〛] &]

In[8]:= divideRelation[n_Integer] := Select[Tuples[Range[n], 2], Divisible[#〚2〛, #〚1〛] &]

In[9]:= inverseRelation[R _ ? relationQ] := reverse[R, 2]

In[10]:= FindDomain[R _ ? relationQ] := Union[Flatten[R, 1]]

In[11]:= reflexiveQ[R _ ? relationQ] := Modulea, domain, domain = FindDomain[R];


CatchDoIf[! MemberQ[R, {a, a}], Throw[False]], a, Domain;
Throw[True]

In[12]:= symmetricQ[R _ ? relationQ] :=


Module[{u}, Catch[Do[If[! MemberQ[R, Reverse[u]], Throw[False]], {u, R}];
Throw[True]]]

In[13]:= antisymmetricQ[R _ ? relationQ] :=


Module[{u}, Catch[Do[If[! MemberQ[R, Reverse[u]] && u〚1〛 ≠ u〚2〛, Throw[False]], {u, R}];
Throw[True]]]

In[20]:= partialorderQ[R _ ? relationQ] := reflexiveQ[R] && antisymmetricQ[R] && transitiveQ[R]

In[15]:= transitiveQ[R _ ? relationQ] := Moduledomain, a, b, c, domain = FindDoamin[R];


CatchDoIf[! MemberQ[R, {a, b}] && MemberQ[{b, c}] && MemberQ[{a, c}], Throw[False]],
a, domain, b, domain, c, domain;
Throw[True]

Syntax: Expression
"Module[{domain, a, b, c}, domain = FindDoamin[R]; Catch[Do[If[! MemberQ[R, {a, b}] && MemberQ[{b, c}] &&
MemberQ[{a, c}], Throw[False]], {a, domain}, {b, domain}, {c, domain}; Throw[True]]]"
has no closing "]".

In[25]:= LessRelationQ[R _ ? relationQ] := Select[Tuples[A, 2], Lessequal[#〚2〛, #〚1〛] &]

In[21]:= p = {1, 2, 3, 4, 5, 6};


dividesRelation[p]
Out[22]=
{{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 2}, {2, 4}, {2, 6}, {3, 3}, {3, 6}, {4, 4}, {5, 5}, {6, 6}}

In[26]:= partialorderQ[p]
Out[26]=
partialorderQ[{1, 2, 3, 4, 5, 6}]
2

In[27]:= R3 = {1, 1}, {1, 4}, {2, 2}, {2, 5}, {3, 3}, {3, 6} {4, 1}, {4, 4}, {5, 2}, {5, 5}, {6, 3}
Out[27]=
{{1, 1}, {1, 4}, {2, 2}, {2, 5}, {3, 3}, {12, 6}, {4, 4}, {5, 2}, {5, 5}, {6, 3}}

You might also like