Relational Database Design decomposition and closure? - closures

I have been trying to solve these two questions, but haven't had much luck.
Question 1: Show that the decomposition rule:
A → BC implies A → B and A → C,
is a sound rule, namely, that the functional dependencies A → B and A → C
are logically implied by the functional dependency A → BC.
Question 2: Let F be the following collection of functional dependencies
for relation schema R = (A, B, C, D, E):
D → A
BA → C
C → E
E → DB .
a) Compute the closure F + of F .
b) What are the candidate keys for R? List all of them.
c) List the dependencies in the canonical cover of the above set of
dependencies F (in other words, compute F c , as we have seen in class).
Any input will be helpful.

Related

Closure of rational languages under morphism

I have to prove that the set of rational or regular languages is closed by morphism on their alphabet.
i.e. that the image of a rational language by a morphism is still rational.
h being a morphism from Σ to Σ', my idea is to start with an automaton A and to construct an automaton A' which recognizes the language h(L(A)).
I use the same initial and final states then, for any transition (q, a, q') in A, I consider 3 cases :
if h(a) = ε I add the states q, q' (if they do not already exist in A') and an ε transition (q, ε, q')
if h(a) = b ∈ Σ', I add the states q, q' (if they do not already exist in A') and a transition (q, b, q')
if h(a) = b_1b_2...b_n ∈ Σ'*, I add the states q, q' (if they do not already exist in A') plus n-1 new states and n transitions from (q, b_1, q_1) to (q_{n-1}, b_n, q')
Then it's "easy" to prove that h(L(A)) is included in L(A') following the construction steps, however I'm struggling to prove the converse, i.e. that L(A') is included in h(L(A))

Understanding unquoteDecl in Agda

I'm trying to understand Agda's built in reflection mechanisms, so I decided to write a simple function that takes a string for an identifier,
a quoted type, and a quoted term, and simply defines a term of the given type with the given string identifier. Thus, I wrote the following:
testDefineName' : String → TC Type → TC Term → TC ⊤
testDefineName' s t a =
bindTC (freshName s)
(λ n → bindTC t
(λ t' → bindTC a
(λ a' → (bindTC (declareDef (arg (arg-info visible relevant) n) t')
(λ _ → defineFun n ((clause [] a') ∷ []))))))
unquoteDecl = (testDefineName' "test" (quoteTC ℕ) (quoteTC zero))
This type-checks, but, when I try to use "test" elsewhere I get a Not in scope: test error.
The documentation for unquoteDecl is kind of opaque. Appaently declarations should be of the form
unquoteDecl x_1 x_2 ... x_n = m
where the x_i are Names, and m has type TC \top, so maybe what I was trying to do isn't actually possible, but I still don't understand how this mechanism works: if m has to be of type TC ⊤, and thus cannot be a function of the names x_1 x_2 ... x_n, I don't see how it is possible to bring any new names into scope using unquoteDecl at all!
So, to sum up:
Is it possible to define a function like mine using Agda's reflection mechanism so that I can bring new names into scope using a String argument? What I want is something like:
<boilerplate code for unquoting> testDefineName' "test" (quoteTC ℕ) (quoteTC zero)
test' : ℕ
test' = test
to compile (i.e. I can actually use the new name, "test")
and if not, by what mechanism can m make use of the names x_1 ... x_n? Can m actually have a type like List Name → TC ⊤, contrary to the documentation?
Based on the way Ulf uses unquoteDecl, I have the impression that you need to list on the LHS the names which are going to extend the scope.
The problem with your setup is that you don't know the Name as you generate a fresh one from a String and have no way of getting hold of it AFAIK. I have the impression that freshName is only supposed to be used to generate internal names from inside a tactic.
If you make testDefineName' take a Name rather than a String then everything works out:
testDefineName' : Name → TC Type → TC Term → TC ⊤
testDefineName' n t a = bindTC t
$ λ t' → bindTC a
$ λ a' → bindTC (declareDef (arg (arg-info visible relevant) n) t')
$ λ _ → defineFun n ((clause [] a') ∷ [])
unquoteDecl test = testDefineName' test (quoteTC ℕ) (quoteTC zero)

how to interpret REL in agda

I'm trying to understand some parts of the standard library of Agda, and I can't seem to figure out the definition of REL.
FWIW here's the definition of REL:
-- Binary relations
-- Heterogeneous binary relations
REL : ∀ {a b} → Set a → Set b → (ℓ : Level) → Set (a ⊔ b ⊔ suc ℓ)
REL A B ℓ = A → B → Set ℓ
I can't find any documentation online explaining this, which is why I'm asking here. How does this define a binary relation?
#RodrigoRibeiro's answer explains the Level bits, but once you get rid of universe levels, what does the type Set → Set → Set have to do with binary relations?
Suppose you have a binary relation R ⊆ A × B. The propositional way of modeling it is to create some indexed type R : A → B → Set such that for any a : A, b : B, R a b has inhabitants iff (a, b) ∈ R. So if you want to talk about all relations over A and B, you have to talk about all A- and B- indexed types, i.e. you have to talk about RelationOverAandB = A → B → Set.
If you then want to abstract over the relation's left- and right-hand base type, that means the choice of A and B are not fixed anymore. So you have to talk about REL, such that REL A B = A → B → Set.
What, then, is the type of REL? As we have seen from the REL A B example, it takes the choice of A and B as two arguments; and its result is the type A → B → Set.
So to summarize: given
A : Set
B : Set
we have
REL A B = A → B → Set
which itself has type Set (remember, we're ignoring universe levels here).
And thus,
REL : Set → Set → Set ∎
I guess it's easier to look at an example:
import Level
open import Relation.Binary
open import Data.Nat.Base hiding (_≤_)
data _≤_ : REL ℕ ℕ Level.zero where
z≤n : ∀ {n} -> 0 ≤ n
s≤s : ∀ {n m} -> n ≤ m -> suc n ≤ suc m
The type signature is equivalent to
data _≤_ : ℕ -> ℕ -> Set where
So _≤_ is a relation between two natural numbers. It contains all pairs of numbers such that the first number is less or equal than the second. In the same way we can write
open import Data.List.Base
data _∈_ {α} {A : Set α} : REL A (List A) Level.zero where
here : ∀ {x xs} -> x ∈ x ∷ xs
there : ∀ {x y xs} -> x ∈ xs -> x ∈ y ∷ xs
The type signature is equivalent to
data _∈_ {α} {A : Set α} : A -> List A -> Set where
_∈_ is a relation between elements of type A and lists of elements of type A.
The universe monomorphic variant of REL is itself a binary relation:
MonoREL : REL Set Set (Level.suc Level.zero)
MonoREL A B = A → B → Set
To define a binary relation we need two sets, so REL needs, at least, two types. The type of REL:
REL : ∀ {a b} → Set a → Set b → (ℓ : Level) → Set (a ⊔ b ⊔ suc ℓ)
This type is a bit polluted due to universe level stuff. If you allow yourself a bit of informality, you can disable universe levels (more information about this here) and write REL as:
REL : Set -> Set -> Set
which is a type that expects two types as parameters.
The use of universes in type theory is to avoid paradoxes like Russell's Paradox of set theory.
I'm not a type theory expert, but the interpretation of REL type can be summarised as:
Set a and Set b are parameters types of universe levels a andb, respectively.
The operator ⊔ returns the maximum of two parameter levels.
Hope that this can help you.

Is it possible to get hold of free theorems as propositional equalities?

"Free theorems" in the sense of Wadler's paper "Theorems for Free!" are equations about certain values are derived based only on their type. So that, for example,
f : {A : Set} → List A → List A
automatically satisfies
f . map g = map g . f
Can I get my hands on an Agda term, then, of the following type:
(f : {A : Set} → List A → List A) {B C : Set} (g : B → C) (xs : List B)
→ f (map g xs) ≡ map g (f xs)
or if so/if not, can I do something more/less general?
I'm aware of the existence of the Lightweight Free Theorems library but I don't think it does what I want (or if it does, I don't understand it well enough to do it).
(An example use case is that I have a functor F : Set → Set and would like to prove that a polymorphic function F A × F B → F (A × B) is automatically a natural transformation.)
No, the type theory on which Agda is build is not strong enough to prove this. This would require a feature called "internalized parametricity", see the work by Guilhem:
Jean-Philippe Bernardy and Guilhem Moulin: A Computational Interpretation of Parametricity (2012)
Guilhem Moulin: Pure Type Systems with an Internalized Parametricity Theorem (2013)
This would allow you for example to prove that all inhabitants of "(A : Set) → A → A" are equal to the (polymorphic) identity function. As far as I know, this has not been implemented in any language yet.
Chantal Keller and Marc Lasson developped a tactic for Coq generating the parametricity relation corresponding to a (closed) type and proving that this type's inhabitants satisfy the generated relation. You can find more details about this work on Keller's website.
Now in Agda's case, it is in theory possible to do the same sort of work by implementing the tactic in pure Agda using a technique called reflection.

Dependency Preserving in decomposition of tables

I am confused with dependency preserving property of database relations (tables). Do we have to look at initial FD set or what else? I tried to solve some problems on this subject. The questions before this one all feed my initial estimation, which is 'look at the given FD set. If you don't lose any of them in your new relation set, then this is dependency preserving'.
But when I come to this question I am confused.
Consider the relation R = (A B C D E F G H) and the following FD set:
FD1 E -› D
FD2 B, E -› C G
FD3 D, G -› E
FD4 C -› A B
FD5 E, G -› C
FD6 A, E -› B D
FD7 C, E, D -› G
FD8 A, G -› E
These are the given relations
R1 (E F G H)
R2 (A B E G)
R3 (C D E G)
R4 (A B C)
Answer says that this decomposition is dependency preserving. According to my estimation we lose FD2 so, this must not be dependency preserving.
I need an expert to clarify this concept for me.
This question was a part of homework questions. I wasn't sure if I am thinking right when I do the homework.
In my answer I wrote:
This decomposition is not dependency preserving because in this decomposition we loose the FD DF--> BC .
And my database teacher accepted this answer as an right answer I wanted to clearify the subject here also.
Ferda
The decomposition is dependency preserving as FD2 BE->CG can be achieved by relations R2(BE->G) and R3(EG->C).
Closure of BE gives CG.

Resources