2

Is there way to rewrite natural join of two matrices filled with numbers in terms of ordinary calculus and linear algebra notation (in terms of things like vector products or matrix products, vector addition or matrix addition or something else thought in these courses)? Natural join is $R \bowtie S =\{\, (a, b, c)\mid (a, b) \in S \land (d, c) \in R \land b=d \,\}$. I know that matrices and relations are not same things, so I want matrix function that would act similar to natural join.

As far I have got, is this: $C(1,j)=A(1,j) \land C(2,j)=A(2,j)\land C(3,k)= B(2,k) \land A(2,j)=B(1,k)$, where A and B are matrices corresponding to relations $S$ and $R$, and $C$ is a matrix corresponding to $R \bowtie S$.

UPDATE: IF $R=\{\ (a_{1,1},a_{1,2}), (a_{2,1},a_{2,2}),(a_{3,1},a_{3,2})\}\ $then $A=\begin{pmatrix} a_{1,1} & a_{1,2} \\ a_{2,1} & a_{2,2} \\ a_{3,1} & a_{3,2} \end{pmatrix} $

IF $S=\{\ (b_{1,1},b_{1,2}), (b_{2,1},b_{2,2}),(b_{3,1},b_{3,2})\}\ $then $B=\begin{pmatrix} b_{1,1} & b_{1,2} \\ b_{2,1} & b_{2,2} \\ b_{3,1} & b_{3,2} \end{pmatrix} $

C is matrix, that rows of that corresponds to ordered triples defined by set $\{\, (a, b, c)\mid (a, b) \in S \land (d, c) \in R \land b=d \,\}$

Similarly it is possible to define A, B, C with any number of rows.

How can I define matrix C using ordinary calculus, linear algebra or matrix calculus notation?

Alex Alex
  • 333
  • 1
    How do you define a matrix $A$ corresponding to relation $R$? I could imagine $A_{ij}=1$ if $R(i,j)$ and $0$ otherwise, but then it's not an arbitrary matrix. And how do you define a matrix $C$ corresponding to $R \bowtie S$? – Jean-Claude Arbaut Jun 29 '21 at 05:16
  • About what are A, B and C see in update. – Alex Alex Jun 29 '21 at 07:20
  • Your matrices aren't well defined: while the relations ${(a,b),(c,d)}$ and ${(c,d),(a,b)}$ are the same, since sets aren't ordered, the matrices $(\begin{smallmatrix} a&b\c&d\end{smallmatrix})$ and $(\begin{smallmatrix}c&d\a&b\end{smallmatrix})$ are different. – Christoph Jun 29 '21 at 07:25
  • I know that. I want order of rows in C to be same as in A. – Alex Alex Jun 29 '21 at 07:30

1 Answers1

1

The short answer is: no there is no ordinary matrix calculus way to define such a natural join of two $n\times 2$ matrices.

Here's the best description I can come up with on the spot:

Let $A$ be a $n\times 2$ matrix and $B$ be a $m\times 2$ matrix corresponding to relations $R$ with $|R|=n$ and $S$ with $|S|=m$, respectively.

Denote the rows of $A$ and $B$ by $A_i$ and $B_i$. Now first form the $(nm)\times 4$ matrix given as $$ C'= \begin{pmatrix} A_1 & \\ \vdots & \Large B \\ A_1 & \\\hline A_2 & \\ \vdots & \Large B \\ A_2 & \\\hline \Large{\vdots} & \Large{\vdots} \\\hline A_n & \\ \vdots & \Large B \\ A_n & \end{pmatrix}. $$ This is similar to but different from a Kronecker product.

From $C'$ delete all rows in which the entries in columns $2$ and $3$ are different, then delete one of the (now identical) columns $2$ or $3$. Call the new matrix $C$.

Now the rows of $C$ correspond to the triples in $R\bowtie S$.

Christoph
  • 25,552