The Personnel example
Lax392996.PersonnelExample · concepts/Lax392996/PersonnelExample.lean · lax-392996
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Example
The running example of the paper: the relation of arity 4 with seven tuples, giving an id, a name, a position and a city (1, Juma, Director, Nairobi; 2, Paul, Janitor, Nairobi; 3, David, Analyst, Paris; 4, Ellen, Field agent, Beijing; 5, Aaheli, Double agent, Paris; 6, Nancy, HR, Paris; 7, Jing, Analyst, Beijing), the database holding it, and the query asking for the cities where at least two persons work, , the join being a selection over a cross product. Values are strings, ordered as strings; the claim is Example 2, .
Concept map
In the paper
- page 3 of this submission's paper
Lean source view on GitHub
| 1 | import Mathlib.Data.Fin.VecNotation |
| 2 | import Mathlib.Data.String.Basic |
| 3 | import Mathlib.Data.Multiset.Basic |
| 4 | import Lax392996.Databases |
| 5 | import Lax392996.RelationalAlgebra |
| 6 | import Lax392996.MultisetSemantics |
| 7 | |
| 8 | /-! |
| 9 | --- |
| 10 | title: The Personnel example |
| 11 | type: example |
| 12 | --- |
| 13 | The running example of the paper: the relation of |
| 14 | arity 4 with seven tuples, giving an id, a name, a position and a city |
| 15 | (1, Juma, Director, Nairobi; 2, Paul, Janitor, Nairobi; 3, David, Analyst, |
| 16 | Paris; 4, Ellen, Field agent, Beijing; 5, Aaheli, Double agent, Paris; |
| 17 | 6, Nancy, HR, Paris; 7, Jing, Analyst, Beijing), the database holding |
| 18 | it, and the query asking for the cities where at least two persons work, |
| 19 | |
| 20 | , the join being |
| 21 | a selection over a cross product. Values are strings, ordered as strings; |
| 22 | the claim is Example 2, |
| 23 | . |
| 24 | -/ |
| 25 | |
| 26 | namespace Lax392996.PersonnelExample |
| 27 | |
| 28 | open Lax392996.Databases Lax392996.RelationalAlgebra Lax392996.MultisetSemantics |
| 29 | |
| 30 | /-- Strings as values, ordered as strings; the arithmetic of terms, which |
| 31 | the example does not use, is trivial on them. -/ |
| 32 | instance instValueTypeString : ValueType String where |
| 33 | zero := "" |
| 34 | add _ _ := "" |
| 35 | sub _ _ := "" |
| 36 | mul _ _ := "" |
| 37 | add_comm _ _ := rfl |
| 38 | add_assoc _ _ _ := rfl |
| 39 | |
| 40 | /-- The relation `Personnel` of the paper's Table 1: id, name, position, city. -/ |
| 41 | def personnel : Relation String 4 := Multiset.ofList [ |
| 42 | !["1", "Juma", "Director", "Nairobi"], |
| 43 | !["2", "Paul", "Janitor", "Nairobi"], |
| 44 | !["3", "David", "Analyst", "Paris"], |
| 45 | !["4", "Ellen", "Field agent", "Beijing"], |
| 46 | !["5", "Aaheli", "Double agent", "Paris"], |
| 47 | !["6", "Nancy", "HR", "Paris"], |
| 48 | !["7", "Jing", "Analyst", "Beijing"]] |
| 49 | |
| 50 | /-- The database `I`, with its one relation. -/ |
| 51 | def instanceI : Database String := [("Personnel", ⟨4, personnel⟩)] |
| 52 | |
| 53 | /-- The query `q_city`: the cities where at least two persons work, as |
| 54 | duplicate elimination of a projection of a selection over the cross |
| 55 | product of `Personnel` with itself. Attributes are numbered from 0 here, |
| 56 | from 1 in the paper. -/ |
| 57 | def qcity : Query String 1 := |
| 58 | Query.Dedup (Query.Proj ![Term.index 3] |
| 59 | (Query.Sel (Selection.And (Selection.BT (BoolTerm.EQ (Term.index 3) (Term.index 7))) |
| 60 | (Selection.BT (BoolTerm.LT (Term.index 0) (Term.index 4)))) |
| 61 | (@Query.Prod _ 4 4 8 rfl (Query.Rel 4 "Personnel") (Query.Rel 4 "Personnel")))) |
| 62 | |
| 63 | /-- Example 2: the answer of `q_city` on `I`. -/ |
| 64 | axiom qcity_answer : |
| 65 | Query.evaluate qcity instanceI = Multiset.ofList [!["Nairobi"], !["Paris"], !["Beijing"]] |
| 66 | |
| 67 | end Lax392996.PersonnelExample |
| 68 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments