0

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?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Arthur
  • 81
  • 1
  • 1
  • 7
  • 1
    Please give your textbook name & edition--there are many variants of DRC. (Also clarify the scope of quantifiers & the parsing/precedence of operators.) Please read hits googling 'stackexchange homework' & show your steps composing your query with justification that refers to your textbook. Otherwise we would have to do that work instead of just checking it & we can't say where you went right or wrong & explaining what you should do is just rewriting a textbook with a bespoke tutorial & doing your homework for you. – philipxy Dec 04 '18 at 00:04
  • 1
    Your problem statement has a classic ambiguous use of "all": What if there are no predicted events in Milano--do you want the query to return all providers, or none? (This issue about what "all" means & how to be clear is addressed in presentations of kinds of relational division & alternative queries.) To express yourself clearly & precisely always use "for some (value for) x"/"there exists (a value for) x" & "for all (values for) x"/"for every (value for) x". Please clarify. PS Don't you want the query to find "the providers", not "a provider"? PS "`∃pr(ev,pr)`" doesn't make sense. – philipxy Dec 04 '18 at 01:29

1 Answers1

1

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))
     ))
}
philipxy
  • 14,867
  • 6
  • 39
  • 83