Navigation
Synopsis Transitive closure on binary list relation values.
Syntax Exp +
Types
Exp Exp +
lrel[T1, T2] lrel[T1, T2]
Description Returns the transitive closure of a binary listrelation. Transitive closure is defined by repeated composition of a relation. If we define for a given relation R:
  • R1 = R
  • R2 = R o R
  • R3 = R o R2
  • ...
then the transitive closure R+ can be defined as
  • R+ = R1 + R2 + R3 + ...
Examples
rascal>[<1,2>, <2,3>, <3,4>]+;
lrel[int,int]: [
  <1,2>,
  <2,3>,
  <3,4>,
  <1,3>,
  <2,4>,
  <1,4>
]
We can also simply (but not necessarily efficiently) define transitive closure ourselves:
rascal>lrel[int,int] tclosure(lrel[int,int] R) {
>>>>>>>   tc = R;
>>>>>>>   while(true){
>>>>>>>      tc1 = tc;
>>>>>>>      tc += tc o R;
>>>>>>>      if(tc1 == tc)
>>>>>>>         return tc;
>>>>>>>   }
>>>>>>>}
lrel[int,int] (lrel[int,int]): lrel[int,int] tclosure(lrel[int,int]);
rascal>tclosure([<1,2>, <2,3>, <3,4>]);
interrupted:
	at tclosure(/:6,6)
	at ___SCREEN_INSTANCE___(/:1,0)


Questions
Question [1].
The type of [<3,2>,<2,1>,<1,2>,<2,3>]+ is

Question [2].
[<4,3>,<4,3>,<1,2>,<2,3>,<3,4>]+ == 



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.