3. Calcolo delle Tuple

Le interrogazioni si scrivono al seguente modo: {t | p(t)} —> tutte le tuple per le quali è vera p(t), che è una formula costruita tramite atomi.

Gli atomi sono:

Formule Ben Formate

Esempio di Calcolo delle Tuple

{ t | ∃t1∈\exists t_1\in Studente, ∃t2∈\exists t_2\in Esame, ∃t3∈\exists t_3\in Corso (

t[NOME] = t1[NOME] ∧\wedge

t1[MATR] = t2[MATR] ∧\wedge

t2[C-CORSO] = t3[C-CORSO] ∧\wedge

t2[VOTO] = 30 ∧\wedge

t3[TITOLO] = “matematica”)}

Proprietà importanti

p∧r≡¬(¬p∨¬r)p\wedge r \equiv \lnot(\lnot p \vee \lnot r)

∀t∈r(p(t))≡¬∃t∈r(¬p(t))\forall t \in r (p(t)) \equiv \lnot \exists t \in r (\lnot p(t))

p→r≡¬p∨rp\rightarrow r \equiv \lnot p \vee r

Formule come {t | t ∉\notin r} sono dette unsafe e producono risultati infiniti.

Per rimanere in un ambito safe si restringe la formulazione del calcolo delle formule ai domini attivi: le tuple che soddisfano una formula possono essere composte solamente da valori che compaiono:

Equivalenza tra Algebra Relazionale e Calcolo delle Tuple

Selezione: σA=1R={t∣∃t1∈R(t1[A]=1)∧t=t1}\sigma_{A=1}R = \{ t | \exists t_1 \in R (t_1[A] = 1) \wedge t = t_1 \}

Proiezione: ΠA,CR={t∣∃t1∈R(t[A,C]=t1[A,C])}\Pi_{A,C}R = \{t|\exists t_1\in R(t[A, C]=t_1[A, C])\}

Prodotto Cartesiano: R(A,B,C)×S(D,E,F)={t∣∃t1∈R,∃t2∈S(t[A,B,C]=t1[A,B,C]∧t[D,E,F]=t2[D,E,F])}R(A, B, C)\times S(D, E, F) = \{t|\exists t_1\in R, \exists t_2\in S (t[A, B, C]=t_1[A, B,C] \wedge t[D, E, F]=t_2[D, E, F])\}

Unione: R∪S={t∣(∃t1∈r(t=t1)∨(∃t2∈s(t=t2)}R\cup S = \{t| (\exists t_1\in r (t=t_1) \vee (\exists t_2\in s (t = t_2)\}

Differenza: R−S={t∣(∃t1∈r(t=t1)∧¬(∃t2∈s(t=t2)}R-S=\{t| (\exists t_1\in r (t=t_1) \wedge \lnot (\exists t_2\in s (t = t_2)\}