index | submit | rank | book

rel-composition – Relation composition

Write a program that is able to compose binary relations. Given relation R and relation S, it should compute relation RS, in other words, “R;S”, “R before S”, “S∘R” or “S after R”.

Relation composition

Input and output

Input begins with a number n indicating the size of domain and codomain. Followed by 2n lines with two matrix representations of relations R and S. The same repeats again. For each pair of relations R and S given in the input, your program should produce a matrix representation of the resulting RS relation.

Example input

3
0 1 1
0 0 1
0 0 0
0 0 0
1 0 0
1 1 0
4
1 1 1 1
0 1 0 0
0 0 1 0
1 1 1 1
1 0 0 1
1 1 0 1
1 0 1 1
1 0 0 1

Example output

1 1 0
1 1 0
0 0 0
1 1 1 1
1 1 0 1
1 0 1 1
1 1 1 1

Scoring

try first: rel-member

try also: rel-properties

try next: gcd

index | submit | rank | book

Copyright © 2020-2021 Rudy Matela
All rights reserved