about query in domain relational calculus

89 views Asked by At

There are 2 relations:

Prediction(cname, etype)

Measures(etype, provider)

cname - city name of predicted future disaster.

etype - event type. earthquake, tsunami...

provider - police, ambulance...

I need to write a query using domain relational calculus and it should find a provider that provides service to all predicted events in Milano.

I have this so far:

{<P> | ∃et <et,P> ∈ Measures ^ ∀ ev (<'Milano', ev> ∈ Prediction 
⟹  ∃pr(ev,pr) ^ pr=P)}

I am not sure about it. Is it ok? or something is wrong?

1

There are 1 answers

0
philipxy On

You don't give a reference to your version of RA (relational algebra) or DRC (domain relational calculus). I'll guess some syntax from your attempt.

-- <cname, etype> rows where city cname suffers event type etype
-- { <cname, etype> | city cname can suffer event type etype }
Provider

-- <etype, provider> rows where event type etype service is provided by provider
-- { <etype, provider> | event type etype is service is provided by provider}
Measures

provider that provides service to all predicted events in Milano.

That is a classic ambiguous use of "all"/"every". If no event types happen in Milano, do you want all providers or no providers? (This is a common issue in queries calculated via variants of relational division.)

Maybe you want providers p where for all types e, if Milano suffers e then p services e:

-- <p> rows where
    (for all e (
       if city 'Milano' suffers event type e then event e service is provided by p))

{ <p> | (forall e (if <'Milano', e> ∈ Prediction then <e, p> ∈ Measures)) }

But from your query it seems like maybe you want providers p where there is a type that Milano suffers & for all types e, if Milano suffers e then p services e:

-- <p> rows where
    (for some e ('Milano' suffers event type e))
&   (for all e (
       if city 'Milano' suffers event type e then event e service is provided by p))

{ <p> |
    (exists e (<'Milano', e> ∈ Prediction))
&   (forall e (if <'Milano', e> ∈ Prediction then <e, p> ∈ Measures))
}

Your query seems to be trying to be like the following complication of that:

{ <p> |
    (exists e (<'Milano', e> ∈ Prediction))
&   (forall e (
        if <'Milano', e> ∈ Prediction
        then (exists pr (<e, pr> ∈ Measures & pr = p))
     ))
}