The Personnel example, rewritten
Lax392996.RewritingExample · concepts/Lax392996/RewritingExample.lean · lax-392996
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Example
The paper's Example 11: the rewriting rules applied bottom up to , for any annotation type , give , the cross product rewritten by (R2), the projection by (R1) and the duplicate elimination by (R3), the selection carried over to the composite tuples. The claim is that equation, on the queries as syntax; the equality of its two semantics is an instance of the correctness theorem. Attributes are numbered from 0 here, from 1 in the paper.
Concept map
In the paper
- page 5 of this submission's paper
Lean source view on GitHub
| 1 | import Mathlib.Data.Fin.VecNotation |
| 2 | import Lax392996.Databases |
| 3 | import Lax392996.RelationalAlgebra |
| 4 | import Lax392996.RewritingRules |
| 5 | import Lax392996.PersonnelExample |
| 6 | |
| 7 | /-! |
| 8 | --- |
| 9 | title: The Personnel example, rewritten |
| 10 | type: example |
| 11 | --- |
| 12 | The paper's Example 11: the rewriting rules applied bottom up to |
| 13 | , for any annotation type , give |
| 14 | |
| 15 | , |
| 16 | the cross product rewritten by (R2), the projection by (R1) and the |
| 17 | duplicate elimination by (R3), the selection carried over to the composite |
| 18 | tuples. The claim is that equation, on the queries as syntax; the equality |
| 19 | of its two semantics is an instance of the correctness theorem. Attributes |
| 20 | are numbered from 0 here, from 1 in the paper. |
| 21 | -/ |
| 22 | |
| 23 | namespace Lax392996.RewritingExample |
| 24 | |
| 25 | open Lax392996.Databases Lax392996.RelationalAlgebra Lax392996.RewritingRules |
| 26 | open Lax392996.PersonnelExample |
| 27 | |
| 28 | /-- The rewritten query, as the paper traces it. -/ |
| 29 | def qcityRewritten (K : Type) : Query (String ⊕ K) 2 := |
| 30 | Query.ProvSum (fun k : Fin 1 => k.castLE (by omega)) (Term.index 1) |
| 31 | (Query.Proj ![Term.index 3, Term.index 8] |
| 32 | (Query.Sel (Selection.And (Selection.BT (BoolTerm.EQ (Term.index 3) (Term.index 7))) |
| 33 | (Selection.BT (BoolTerm.LT (Term.index 0) (Term.index 4)))) |
| 34 | (Query.Proj ![Term.index 0, Term.index 1, Term.index 2, Term.index 3, |
| 35 | Term.index 5, Term.index 6, Term.index 7, Term.index 8, |
| 36 | Term.mul (Term.index 4) (Term.index 9)] |
| 37 | (@Query.Prod _ 5 5 10 rfl (Query.Rel 5 "Personnel") (Query.Rel 5 "Personnel"))))) |
| 38 | |
| 39 | /-- Example 11: the rewriting of `q_city` is the traced query. -/ |
| 40 | axiom qcity_rewriting : ∀ (K : Type) (hq : qcity.source), |
| 41 | Query.rewriting (K := K) qcity hq = qcityRewritten K |
| 42 | |
| 43 | end Lax392996.RewritingExample |
| 44 |
Builds on
Used by
none
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments