0

I have these three tables:

 Customer
 Rent
 Book

The cardinality between the Customer and the Rent table is (1,6) and the cardinality between the Rent and the Book table is (1,infinity).

Using relational calculus's syntax, I would define a (0,1) cardinality like this:

∀x∀y∀z(rent(x,y)∧rent(x,z) → y =z)

But how can I define a (1,6) cardinality?

Viktor
  • 2,623
  • 3
  • 19
  • 28
Andrew
  • 1,035
  • 7
  • 22
  • 40
  • Please define exactly what you (think) you mean by cardinality between two tables. Please say what design method you are using. – philipxy Oct 01 '16 at 17:25
  • Do you mean, *predicate calculus*? That's what your example is written in and what we would expect a contraint to be written in. A (domain or tuple) calculus expression denotes a *relation*, although such an expression that returns a relation with no columns can be take as a proposition. PS See my correction & simplification for the accepted answer. – philipxy Oct 24 '16 at 05:02

1 Answers1

0

You could express it (in predicate calculus, as you have expressed your question) in this way:

∀ x (x ∈ Customers →  ∃ y rent(x,y))

∧

∀ x (x ∈ Customers → cardinality ({ y | rent(x,y)}) ≤ 6)

If you prefer, you can write the condition cardinality(set) ≤ n with a complex logical expression of the form:

∀y1∀y2 ... ∀yn (rent(x,y1) ∧ rent(x,y2) ∧ ... ∧ rent(x,yn)
                  ∧ y1 ≠ y2 ^ ... (all the possible pairs) ... 
  → ∄ ys (rent(x,ys)  ∧ ys ≠ y1 ^ ys ≠ y2 ^ ... ^ ys ≠ yn)

or in a more concise way (see the note of @philipxy):

∀y0∀y1 ... ∀yn (rent(x,y0) ∧ rent(x,y1) ∧ ... ∧ rent(x,yn) → y0 = y1 ∨ ... 
Renzo
  • 26,848
  • 5
  • 49
  • 61
  • Your first code block (`cardinality(rent) > 0`) incorrectly has y free in the first conjunct. Since a given x has one or more ys, we get `∀ x (x ∈ Customers → ∃ y rent(x,y))`. A simpler `cardinality(rent) ≤ n` is `∀y0∀y1 ... ∀yn (rent(x,y0) ∧ rent(x,y1) ∧ ... ∧ rent(x,yn) → y0 = y1 ∨ ... (all the possible pairs) ...)`. PS You've given *predicate calculus*, which seems to be what the question meant by "relational calculus". – philipxy Oct 24 '16 at 05:01