Conjunctive queries and graph databases as structures

Lax420092.QueryDatabases · concepts/Lax420092/QueryDatabases.lean · lax-420092

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    An instance of Boolean conjunctive query evaluation is a finite structure over a vocabulary with a unary relation marking the query's variables and two binary relations: the atoms of the query, over variables and constants, and the facts of the database, over constants. The schema is a single binary relation, that of graph databases; a database edge is a fact both of whose endpoints are constants, facts touching a variable being junk the semantics ignores.

    Concept map
    1 concept; 11 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Tactic.FinCases
    2import Mathlib.ModelTheory.Order
    3import Mathlib.ModelTheory.Semantics
    4import Mathlib.ModelTheory.Complexity
    5import Mathlib.Data.Set.Finite.Lemmas
    6import Mathlib.Order.PiLex
    7import Mathlib.Data.Prod.Lex
    8import Mathlib.Data.Fintype.EquivFin
    9import Mathlib.Logic.Equiv.Fin.Basic
    10import Mathlib.Data.Finite.Sigma
    11import Mathlib.Data.Fintype.Lattice
    12import Mathlib.ModelTheory.Syntax
    13import Mathlib.ModelTheory.Graph
    14import Mathlib.Combinatorics.SimpleGraph.Coloring.Vertex
    15import Mathlib.SetTheory.Cardinal.Finite
    16
    17/-!
    18---
    19title: Conjunctive queries and graph databases as structures
    20type: definition
    21---
    22An instance of Boolean conjunctive query evaluation is a finite structure
    23over a vocabulary with a unary relation marking the query's variables and
    24two binary relations: the atoms of the query, over variables and constants,
    25and the facts of the database, over constants. The schema is a single
    26binary relation, that of graph databases; a database edge is a fact both of
    27whose endpoints are constants, facts touching a variable being junk the
    28semantics ignores.
    29-/
    30
    31namespace Lax420092.QueryDatabases
    32
    33open FirstOrder
    34
    35open FirstOrder.Language
    36
    37/-- The relation symbols of the language. -/
    38inductive queryDbRel : ℕ → Type where
    39/-- `isVar x`: the element `x` is a variable of the query. -/
    40 | isVar : queryDbRel 1
    41/-- `atom x y`: the query contains the atom `E(x, y)` (its arguments are
    42 variables or constants). -/
    43 | atom : queryDbRel 2
    44/-- `fact a b`: the database contains the fact `E(a, b)`. -/
    45 | fact : queryDbRel 2
    46 deriving DecidableEq
    47
    48/-- The relational language of BCQ evaluation instances: a query and a
    49database over a shared universe, with a unary predicate singling out the
    50query variables and binary predicates for query atoms and database facts. -/
    51def queryDb : FirstOrder.Language :=
    52 ⟨fun _ => Empty, queryDbRel⟩
    53
    54instance instIsRelationalQueryDb : FirstOrder.Language.IsRelational queryDb := fun _ =>
    55 (inferInstance : IsEmpty Empty)
    56
    57/-- `isVar x`: the element `x` is a variable of the query. -/
    58abbrev qdbIsVar : queryDb.Relations 1 :=
    59 .isVar
    60
    61/-- `atom x y`: the query contains the atom `E(x, y)` (its arguments are
    62 variables or constants). -/
    63abbrev qdbAtom : queryDb.Relations 2 :=
    64 .atom
    65
    66/-- `fact a b`: the database contains the fact `E(a, b)`. -/
    67abbrev qdbFact : queryDb.Relations 2 :=
    68 .fact
    69
    70open FirstOrder
    71
    72open Language Structure BoundedFormula
    73
    74section EvalShorthands
    75
    76variable {A : Type} [queryDb.Structure A]
    77
    78/-- `x` is a variable of the query. -/
    79def QVar (x : A) : Prop := RelMap qdbIsVar ![x]
    80
    81/-- `E(x, y)` is an atom of the query. -/
    82def QAtom (x y : A) : Prop := RelMap qdbAtom ![x, y]
    83
    84/-- `E(a, b)` is a fact of the database (raw: no constraint on `a`, `b`). -/
    85def DbFact (x y : A) : Prop := RelMap qdbFact ![x, y]
    86
    87/-- A genuine database edge: a fact both of whose endpoints are database
    88elements (i.e., not query variables). Facts violating this are representation
    89junk and are ignored by the semantics. -/
    90def DbEdge (x y : A) : Prop := DbFact x y ∧ ¬QVar x ∧ ¬QVar y
    91
    92end EvalShorthands
    93
    94end Lax420092.QueryDatabases
    95

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…