Laboratory Work 2 — Cartesian Products and Relations
Second laboratory work of Computer Discrete Mathematics. You implement the Cartesian product of sets from first principles, then build on it to test and generate binary relations — including relations defined by a predicate and filtered products.
At a glance
| Topic | Ordered pairs, Cartesian product, binary relations as subsets of |
| Prerequisite lectures | L02 — Set algebra, L03 — Relations |
| Deliverable | Source code + report (see 5report.md) |
| Grading | Banded: Easy 60–74 / Medium 75–89 / Hard 90–100 (see 4task.md) |
Contents
| # | Part | File |
|---|---|---|
| 1 | Objective | 1purpose.md |
| 2 | Methodical guidelines (theory & algorithms) | 2method.md |
| 4 | Task and order of execution | 4task.md |
| 5 | Report contents | 5report.md |
| 6 | Control questions | 6questions.md |
Conventions
- Language — source code and the report are in English.
- Implement it yourself — no built-in shortcuts. Do not call a library or
built-in that performs the core task for you (e.g. no
HashSet/set()/Setfor sets, no library graph/relation type, nomath.gcd, noeval). Build the mechanism from basic primitives — arrays/lists, loops, arithmetic, strings. - Deliverable — submit the source code and a report structured as in 5report.md; the code must reproduce the example outputs in 4task.md.
- Self-contained theory — everything needed is in 2method.md; no external material is required.
Summary
The Cartesian product is the set of all ordered pairs drawn from two sets, and a relation is simply a subset of such a product. This makes the product the foundation for everything relational in the course — functions, orders, equivalences, and graphs are all special kinds of relations. In this work you generate products by hand, check that a candidate relation really lives inside , generate relations from a predicate, and filter a product to the pairs that satisfy a condition. The work is graded in three tiers of increasing difficulty.