Help solving a challenge - relational algebra or second order logic

I am a self-taught man and I'm posting my first question here. I'm facing a challenge I'd like to solve. Based on what I know it fits propositional calculus (hope it is).

Suppose 3 people: a captain, a helmsman, a cook. They all come from different countries: Marocco, Korea, Greece (no specific order). They all have different ages: 35, 42, 25 (no specific order).

I know that: The Moroccan man is not a captain; he is not 25. The Greek helmsman is more than 25.

How old is the captain?

Can you please give me some insight on how to solve it? Thanks for your help

-
Since the Moroccan man is not a captain and you know the Greek man is a helmsman, the Korea man must be the captain. Also, since you know that both the Moroccan man and the Greek man are older than 25, the captain must be the age of 25. –  user130512 Feb 27 at 20:36
I'm not sure that this really fits that nicely into a propositional calculus framework. There are three sets here (nationalities, roles, and ages) and functions between them: propositional calculus is not really well adapted to these sorts of problems. –  Unwisdom Feb 27 at 20:38
Thanks user130512. Could you translate it into a propositional calculus-friendly syntax? –  roland Feb 27 at 20:38
@Unwisdom I agree. Relational algebra is what I think. The mathematical model of databases. –  frabala Feb 27 at 20:49

1 Answer

I think it's more natural to think in terms of second order logic here, rather than propositional calculus.

Let $A=\{25,35,42\}$, $R=\{\hat{c},h,c\}$, ($\hat{c}$ is the captain since it has a fancy hat!) and $N=\{K,M,G\}$ be the sets of ages, roles, and nationalities, respectively, and let $f:N\to R$ and $g:N\to A$ be the role and age functions. We assume that $f$ and $g$ are invertible.

We want to identify $g\circ f^{-1}(\hat{c})$.

What do we know?
\begin{eqnarray} && f(M) \neq \hat{c} \\ && g(M) \neq 25 \\ && f(G) =h \\ && g(G) > 25 \end{eqnarray}

Well, $f^{-1}(\hat{c})\in\{G,M,K\}$. But $f^{-1}(h)=G$ so, $f^{-1}(\hat{c})\in\{M,K\}$. We also know that $f(M)\neq \hat{c}$, so $f^{-1}(\hat{c})\neq M$. It must therefore be the case that $f^{-1}(\hat{c})=K$. The captain is the Korean.

So, how old is the Korean? What is $g(K)$? Well, $g$ is onto, but $g(M)\neq 25$ and $g(G)\neq 25$, so we must have $g(K)=25$.

-
Second order logic or, as @frabala notes, relational logic. There's not much difference in this context. –  Unwisdom Feb 27 at 20:57
Thanks a lot, exactly the kind of answer I wanted to read, that is with high formalizm. –  roland Feb 27 at 21:12