A Functorial Query Language

Similar documents
Categorical Databases

Introduction to Olympiad Inequalities

NON-DETERMINISTIC FSA

DATABASE DESIGN I - 1DL300

Discrete Structures Lecture 11

DATABASTEKNIK - 1DL116

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

Finite State Automata and Determinisation

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

LESSON 11: TRIANGLE FORMULAE

Activities. 4.1 Pythagoras' Theorem 4.2 Spirals 4.3 Clinometers 4.4 Radar 4.5 Posting Parcels 4.6 Interlocking Pipes 4.7 Sine Rule Notes and Solutions

On Implicative and Strong Implicative Filters of Lattice Wajsberg Algebras

Linear Algebra Introduction

Alpha Algorithm: A Process Discovery Algorithm

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Section 1.3 Triangles

Functions. mjarrar Watch this lecture and download the slides

8 THREE PHASE A.C. CIRCUITS

BİL 354 Veritabanı Sistemleri. Relational Algebra (İlişkisel Cebir)

Exercise 3 Logic Control

Coalgebra, Lecture 15: Equations for Deterministic Automata

Solutions to Problem Set #1

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

12.4 Similarity in Right Triangles

Lecture 3: Equivalence Relations

Learning Goals. Relational Query Languages. Formal Relational Query Languages. Formal Query Languages: Relational Algebra and Relational Calculus

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

Dorf, R.C., Wan, Z. T- Equivalent Networks The Electrical Engineering Handbook Ed. Richard C. Dorf Boca Raton: CRC Press LLC, 2000

Pre-Lie algebras, rooted trees and related algebraic structures

CHENG Chun Chor Litwin The Hong Kong Institute of Education

6.5 Improper integrals

Lecture 6: Coding theory

CS 573 Automata Theory and Formal Languages

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Part 4. Integration (with Proofs)

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

, g. Exercise 1. Generator polynomials of a convolutional code, given in binary form, are g. Solution 1.

Reference : Croft & Davison, Chapter 12, Blocks 1,2. A matrix ti is a rectangular array or block of numbers usually enclosed in brackets.

Logic Synthesis and Verification

System Validation (IN4387) November 2, 2012, 14:00-17:00

Spacetime and the Quantum World Questions Fall 2010

Hardware Verification 2IMF20

Green s Theorem. (2x e y ) da. (2x e y ) dx dy. x 2 xe y. (1 e y ) dy. y=1. = y e y. y=0. = 2 e

F / x everywhere in some domain containing R. Then, + ). (10.4.1)

SECTION A STUDENT MATERIAL. Part 1. What and Why.?

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Prefix-Free Regular-Expression Matching

ILLUSTRATING THE EXTENSION OF A SPECIAL PROPERTY OF CUBIC POLYNOMIALS TO NTH DEGREE POLYNOMIALS

TOPIC: LINEAR ALGEBRA MATRICES

Nondeterministic Finite Automata

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

INTEGRATION. 1 Integrals of Complex Valued functions of a REAL variable

INF1383 -Bancos de Dados

arxiv: v1 [math.ca] 21 Aug 2018

Generalization of 2-Corner Frequency Source Models Used in SMSIM

Matrices SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics (c) 1. Definition of a Matrix

Algebra Basics. Algebra Basics. Curriculum Ready ACMNA: 133, 175, 176, 177, 179.

3 Angle Geometry. 3.1 Measuring Angles. 1. Using a protractor, measure the marked angles.

2.1 ANGLES AND THEIR MEASURE. y I

Homework 3 Solutions

CS241 Week 6 Tutorial Solutions

ON THE INEQUALITY OF THE DIFFERENCE OF TWO INTEGRAL MEANS AND APPLICATIONS FOR PDFs

expression simply by forming an OR of the ANDs of all input variables for which the output is

THE PYTHAGOREAN THEOREM

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Hyers-Ulam stability of Pielou logistic difference equation

Something found at a salad bar

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

QUADRATIC EQUATION. Contents

u(t)dt + i a f(t)dt f(t) dt b f(t) dt (2) With this preliminary step in place, we are ready to define integration on a general curve in C.

Trigonometry Revision Sheet Q5 of Paper 2

Unit 4. Combinational Circuits

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Math 4310 Solutions to homework 1 Due 9/1/16

6.3.2 Spectroscopy. N Goalby chemrevise.org 1 NO 2 H 3 CH3 C. NMR spectroscopy. Different types of NMR

Line Integrals and Entire Functions

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-378: Computer Hardware Design Winter Notes - Unit 1

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Proportions: A ratio is the quotient of two numbers. For example, 2 3

Lecture 2: January 27

PAIR OF LINEAR EQUATIONS IN TWO VARIABLES

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28

Trigonometry and Constructive Geometry

Chapter 4 State-Space Planning

I 3 2 = I I 4 = 2A

Designing Information Devices and Systems I Fall 2016 Babak Ayazifar, Vladimir Stojanovic Homework 6. This homework is due October 11, 2016, at Noon.

RELATIONAL MODEL.

The Double Integral. The Riemann sum of a function f (x; y) over this partition of [a; b] [c; d] is. f (r j ; t k ) x j y k

Figure 1. The left-handed and right-handed trefoils

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Fundamental Theorem of Calculus

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4

Bisimulation, Games & Hennessy Milner logic

Section 4.4. Green s Theorem

ON LEFT(RIGHT) SEMI-REGULAR AND g-reguar po-semigroups. Sang Keun Lee

AVL Trees. D Oisín Kidney. August 2, 2018

Test Generation from Timed Input Output Automata

Transcription:

A Funtoril Query Lnguge Ryn Wisnesky, Dvid Spivk Deprtment of Mthemtis Msshusetts Institute of Tehnology {wisnesky, dspivk}@mth.mit.edu Presented t Boston Hskell April 16, 2014

Outline Introdution to FQL. FQL is dtse query lnguge sed on tegory theory. But, there will e no tegory theory in this tlk. How to progrm FQL using Hskell. FQL provides n lterntive semntis for Hskell progrms. If you n progrm Hskell, you n progrm FQL. Demo of the FQL E. Projet wepge: tegorildt.net/fql.html 2 / 30

Introdution to FQL In FQL, dtse shem is speil kind of entity-reltionship (ER) digrm. mnger Emp worksin seretry Dept first lst nme Emp.mnger.worksIn Emp.worksIn Emp mgr works first lst 101 103 q10 Al Akin 102 102 x02 Bo Bo 103 103 q10 Crl Cork Dept.seretry.worksIn Dept Dept se nme q10 102 CS x02 101 Mth 3 / 30

Introdution to FQL mnger Emp worksin seretry Dept first lst nme Emp.mnger.worksIn Emp.worksIn Dept.seretry.worksIn Dept Eh lk node represents n entity set (of s). Eh direted edge represents foreign key. Eh open irle represent n ttriute. Dt integrity onstrints re pth equlities. Dt is stored s tles in the ovious wy. 4 / 30

Why FQL? FQL is lnguge for mnipulting the shems nd instnes just defined. But you n lso mnipulte suh shems nd instnes using SQL. We ssert tht, euse of its tegoril roots, FQL is etter lnguge for doing so. FQL is dtse t time, not tle t time. FQL opertions neessrily respet onstrints. Unlike SQL, FQL is expressive enough to e used for informtion integrtion (see ppers). Prts of FQL n run on SQL, nd vie vers. 5 / 30

FQL Bsis A shem mpping F : S Ñ T is onstrint-respeting mpping: nodespsq Ñ nodespt q edgespsq Ñ pthspt q nd it indues three dt migrtion opertions: F : T -inst Ñ S-inst (like projetion) ΣF : S-inst Ñ T -inst (like union) ΠF : S-inst Ñ T -inst (like join) 6 / 30

(Projet) Nme Nme Slry N1 N2 F ÝÝÝÑ N Slry Age Age N1 Nme Slry 1 Bo $250 2 Sue $300 3 Alie $100 N2 Age 1 20 2 20 3 30 F ÐÝÝ N Nme Age Slry 1 Bo 20 $250 2 Sue 20 $300 3 Alie 30 $100 7 / 30

Π (Join) Nme Nme Slry N1 N2 F ÝÝÝÑ N Slry Age Age N1 Nme Slry 1 Bo $250 2 Sue $300 3 Alie $100 N2 Age 1 20 2 20 3 30 Π F ÝÝÑ N Nme Age Slry 1 Alie 20 $100 2 Alie 20 $100 3 Alie 30 $100 4 Bo 20 $250 5 Bo 20 $250 6 Bo 30 $250 7 Sue 20 $300 8 Sue 20 $300 9 Sue 30 $300 8 / 30

Σ (Union) Nme Nme Slry N1 N2 F ÝÝÝÑ N Slry Age Age N1 Nme Slry 1 Bo $250 2 Sue $300 3 Alie $100 N2 Age 1 20 2 20 3 30 Σ F ÝÝÑ N Nme Age Slry 1 Alie null $100 2 Bo null $250 3 Sue null $300 4 null 20 null 5 null 20 null 6 null 30 null 9 / 30

Foreign keys Nme Nme Slry N1 f N2 F ÝÝÝÑ N Slry Age Age N1 Nme Slry f 1 Bo $250 1 2 Sue $300 2 3 Alie $100 3 N2 Age 1 20 2 20 3 30 F ÐÝÝ Π F,Σ F ÝÝÝÝÑ N Nme Age Slry 1 Alie 20 $100 2 Bo 20 $250 3 Sue 30 $300 10 / 30

FQL Summry FQL provides dtse t time query lnguge for ertin kinds of reltionl dtses. For the tegorilly inlined, roughly: Shems re finitely-presented tegories. Shem mppings re funtors. Instnes re funtors to the tegory of sets. The instnes on ny shem form tegory. pσf, F q nd p F, Π F q re djoint funtors. 11 / 30

Progrmming FQL Shems nd Mppings using Hskell By Hskell, I men the the simply-typed λ-lulus (STLC): Types t: t :: 0 1 t ` t t ˆ t t Ñ t Expressions e: e :: v λv : t.e ee pq fst e snd e pe, eq K inl e inr e pe ` eq Equtions: fstpe, fq e sndpe, fq f pλv : t.eqf erv ÞÑ fs... Theorem: FQL shems nd mppings re model of the STLC. Given n STLC type t, you get n FQL shem rts. Given n STLC term Γ $ e : t, you get n FQL shem mpping res : rγs Ñ rts 12 / 30

Progrmming FQL Shems using Hskell The empty type, 0, (in Hskell, dt Empty = ), eomes shem with no nodes: The unit type, 1, (in Hskell, dt Unit = TT), eomes shem with one node: TT 13 / 30

Progrmming FQL Shems using Hskell Sum types, t ` t 1, (in Hskell, Either t t ), re given y ddition: inl inl inl ` d e inr d inr e Produt types, t ˆ t 1, (in Hskell, (t,t )), re given y multiplition: p,dq p,dq p,dq ˆ d e p,eq p,eq p,eq 14 / 30

Progrmming FQL Shems using Hskell Funtion types, t Ñ t 1 re given y exponentition: Ñ d e pþñd,þñd,þñdq pþñe,þñd,þñdq pþñd,þñe,þñdq pþñd,þñd,þñeq pþñe,þñe,þñdq pþñd,þñe,þñeq pþñe,þñd,þñeq pþñe,þñe,þñeq 15 / 30

Progrmming FQL Shems using Hskell Constnt types, orresponding to user defined types in Hskell, re simply shems: mnger Emp worksin seretry Dept The opertions ˆ, `, Ñ ehve orretly with respet to foreign keys. Hene, STLC types trnslte to FQL shems. 16 / 30

Progrmming FQL Mppings using Hskell In Hskell, we hve K ::. In FQL, we hve mpping K : 0 Ñ : K ÝÑ mnger Emp worksin seretry Dept In Hskell, we hve pq :: 1. In FQL, we hve mpping pq : Ñ 1: mnger Emp worksin seretry Dept pq ÝÑ TT 17 / 30

Progrmming FQL Mppings using Hskell In Hskell, we hve inl :: Ñ ` nd inr :: Ñ `. ` d e inl,inr ÝÝÝÝÑ inl inl inl inr d inr e In Hskell, we hve fst :: ˆ Ñ nd snd :: ˆ Ñ. ˆ d e fst,snd ÐÝÝÝÝ p,dq p,dq p,dq p,eq p,eq p,eq 18 / 30

Progrmming FQL Mppings using Hskell We n trnslte the other STLC opertions too: If f :: t Ñ nd g :: t Ñ, we need pf, gq :: t Ñ ˆ. This is piring. If f :: Ñ t nd g :: Ñ t, we need pf ` gq :: ` Ñ t. This is se. If f :: ˆ Ñ, we need Λf : Ñ p Ñ q. This is usully lled urry. We need ev :: p Ñ q ˆ Ñ. This is funtion pplition. All FQL opertions oey the required equtions, fstp, q sndp, q... And the FQL opertions work orretly with foreign keys. Hene, FQL mppings re model of the STLC. 19 / 30

Retrospetive STLC types nd terms, FQL shems nd mppings, nd even sets nd funtions etween them, re ll i-rtesin losed tegories. Hskell progrmmers will eventully enounter tegory theory, strting with i-rtesin losed tegories. Tht theory n e put to use in other ples, nmely dtses. In ft, s we will see next, for every FQL shem S, the tegory of S-instnes is lso i-rtesin losed. 20 / 30

Progrmming FQL Instnes nd Morphisms using Hskell By Hskell, I men the the simply-typed λ-lulus (STLC): Types t: t :: 0 1 t ` t t ˆ t t Ñ t Expressions e: e :: v λv : t.e ee pq fst e snd e pe, eq K inl e inr e pe ` eq Equtions: fstpe, fq e sndpe, fq f pλv : t.eqf erv ÞÑ fs... Theorem: For eh shem S, the FQL S-instnes nd S-homomorphisms re model of the STLC. A dtse homomorphism is mp of s to s. Given n STLC type t, you get n FQL S-instne rts. Given n STLC term Γ $ e : t, you get n FQL S-homomorphism res : rγs Ñ rts 21 / 30

Progrmming FQL Instnes using Hskell Let S e the shem f The empty type, 0, (in Hskell, dt Empty = ), eomes n S instne with no dt: f The unit type, 1, (in Hskell, dt Unit = TT), eomes n S instne with one per tle: f 1 1 1 22 / 30

Progrmming FQL Instnes using Hskell Sum types t ` t 1 re given y disjoint union: f 1 3 2 3 3 4 ` f d f inl 1 inl 3 inl 2 inl 3 inr inr inr inr inl 3 inl 4 inr inr d Produt types t ˆ t 1 re given y joining: f 1 3 2 3 3 4 ˆ f d (1,) (1,) (2,) (2,) f (3,) (3,) (3,) (3,) (3,) (3,d) (4,) (4,d) 23 / 30

Progrmming FQL Instnes using Hskell Funtion types t Ñ t 1 re given y finding ll homomorphisms: f 1 3 2 3 3 4 Ñ f d f 1 ÞÑ, 2 ÞÑ, 3 ÞÑ, 4 ÞÑ d 3 ÞÑ, 4 ÞÑ d 1 ÞÑ, 2 ÞÑ, 3 ÞÑ, 4 ÞÑ d 3 ÞÑ, 4 ÞÑ d 1 ÞÑ, 2 ÞÑ, 3 ÞÑ, 4 ÞÑ d 3 ÞÑ, 4 ÞÑ d 1 ÞÑ, 2 ÞÑ, 3 ÞÑ, 4 ÞÑ d 3 ÞÑ, 4 ÞÑ d 1 ÞÑ, 2 ÞÑ, 3 ÞÑ d, 4 ÞÑ 3 ÞÑ d, 4 ÞÑ 1 ÞÑ, 2 ÞÑ, 3 ÞÑ d, 4 ÞÑ 3 ÞÑ d, 4 ÞÑ 1 ÞÑ, 2 ÞÑ, 3 ÞÑ d, 4 ÞÑ 3 ÞÑ d, 4 ÞÑ 1 ÞÑ, 2 ÞÑ, 3 ÞÑ d, 4 ÞÑ 3 ÞÑ d, 4 ÞÑ 3 ÞÑ, 4 ÞÑ 3 ÞÑ, 4 ÞÑ d 3 ÞÑ d, 4 ÞÑ 3 ÞÑ d, 4 ÞÑ d 24 / 30

Progrmming FQL Instnes using Hskell Constnt instnes, orresponding to user defined types in Hskell, re simply instnes: f p q q r t t The opertions ˆ, `, Ñ ehve orretly with respet to foreign keys. Hene, for every shem S, STLC types trnslte to S-instnes. 25 / 30

Progrmming FQL Homomorphisms using Hskell in Hskell, we hve K ::. In FQL, we hve homomorphism K : 0 Ñ : f K ÝÑ p r f q t q t In Hskell, we hve pq :: 1. In FQL, we hve homomorphism pq : Ñ 1: f pq ÝÑ f p q q 1 1 1 r t t 26 / 30

Progrmming FQL Homomorphisms using Hskell As efore, inl : Ñ ` nd inr : Ñ ` f 1 3 2 3 3 4 ` f d inl,inr ÝÝÝÝÑ f inl 1 inl 3 inl 2 inl 3 inr inr inr inr inl 3 inl 4 inr inr d As efore, fst : ˆ Ñ nd snd : ˆ Ñ f 1 3 2 3 3 4 ˆ f d fst,snd ÐÝÝÝÝÝ (1,) (1,) (2,) (2, ) f (3,) (3,) (3,) (3,) (3,) (3,d) (4,) (4,d) 27 / 30

Retrospetive The lnguge of FQL instnes ontins ll opertions required to e model of the STLC. In ft, t the level of instnes, FQL is model of higher-order logi: types t ::... P rop expressions e ::... e e The STLC struture interts with the, Σ, Π dt migrtion opertions in nie wy, e.g,: Σ F pi ` Jq Σ F piq ` Σ F pjq Π F pi ˆ Jq Π F piq ˆ Π F piq 28 / 30

Demo of the FQL E The FQL E is n open-soure jv pplition, downlodle t tegorildt.net{fql.html It supports ll the opertions disussed ove: 0, 1, `, ˆ, Ñ for shems nd instnes, nd the dt migrtion opertions, Σ, Π. To the extent possile, ll opertions re implemented with SQL: 0, 1, `, ˆ,, Π implemented with SQL. Σ F only implementle with SQL if F hs ertin property. Ñ not implementle with SQL. Other fetures: It trnsltes from SQL to FQL. It emits RDF enodings of instnes. It omes with mny uilt-in exmples. It n e used s ommnd-line ompiler. 29 / 30

Conlusion First, we tlked out FQL, funtoril query lnguge sed on tegory theory. Shems re prtiulr ER digrms, nd instnes re reltionl tles. The, Σ, Π opertions migrte dt from one shem to nother. FQL ontins two opies of the STLC: one t the level of shems nd mppings, nd one t the level of instnes nd homomorphisms. Conlusion: Hskell, in the guise of the STLC, ours in mny res of CS outside of progrmming. Finlly, we sw demo of the FQL E. We re looking for ollortors: tegorildt.net/fql.html 30 / 30