@@ -50,51 +50,52 @@ def Query.evaluateT (dbi : DatabaseInstance ρ α μ) (q : Query ρ α) : Set (
5050 | .j sq₁ sq₂ => joinT (sq₁.evaluateT dbi) (sq₂.evaluateT dbi)
5151 | .r f sq => renameT (sq.evaluateT dbi) f
5252 | .u sq₁ sq₂ => unionT (sq₁.evaluateT dbi) (sq₂.evaluateT dbi)
53- | .d sq₁ sq₂ => diffT (sq₁.evaluateT dbi) (sq₂.evaluateT dbi)
53+ | .d sq₁ sq₂ => differenceT (sq₁.evaluateT dbi) (sq₂.evaluateT dbi)
5454
5555/-- Proof that each well-typed query will result in tuples with the correct schema -/
56- theorem Query.evaluate.validSchema [DecidableEq α] (q : Query ρ α) (h : q.isWellTyped dbi.schema) : ∀t, t ∈ q.evaluateT dbi → PFun.Dom t = ↑(q.schema dbi.schema) := by
57- induction q with
58- | R rn =>
59- intro t h_t
60- simp_all only [isWellTyped, evaluateT, schema, ← DatabaseInstance.validSchema]
61- exact (dbi.relations rn).validSchema t h_t
62- | s a b sq ih =>
63- simp_all only [isWellTyped, evaluateT, selectionT, schema]
64- simp_all only [forall_const, Set.mem_setOf_eq, implies_true]
65- | p rs sq ih =>
66- intro t h_t
67- simp_all [isWellTyped, evaluateT, projectionT, schema]
68- apply projectionDom ⟨sq.schema dbi.schema, evaluateT dbi sq, ih⟩ ?_ h.2
69- . simp_all only [projectionT, Set.mem_setOf_eq]
70- | j sq₁ sq₂ ih₁ ih₂ =>
71- intro t h_t
72- simp_all only [isWellTyped, forall_const]
73- apply joinDom
74- ⟨sq₁.schema dbi.schema, evaluateT dbi sq₁, ih₁⟩
75- ⟨sq₂.schema dbi.schema, evaluateT dbi sq₂, ih₂⟩
76- h_t
77- | r f sq ih =>
78- intro t h_t
79- apply renameDom ⟨sq.schema dbi.schema, evaluateT dbi sq, (by simp_all)⟩ h.2 .2
80- simp_all only [evaluateT, renameT, Set.mem_setOf_eq]
81- | u sq₁ sq₂ ih =>
82- intro _ ht
83- simp [isWellTyped, evaluateT, unionT, schema] at *
84- cases ht
85- all_goals simp_all only
86- | d sq₁ sq₂ ih =>
87- intro _ ht
88- simp [isWellTyped, evaluateT, diffT, schema] at *
89- cases ht
90- all_goals simp_all only
56+ theorem Query.evaluate.validSchema {dbi : DatabaseInstance ρ α μ} [DecidableEq α] (q : Query ρ α) (h : q.isWellTyped dbi.schema) :
57+ ∀t, t ∈ q.evaluateT dbi → PFun.Dom t = ↑(q.schema dbi.schema) := by
58+ induction q with
59+ | R rn =>
60+ intro t h_t
61+ simp_all only [isWellTyped, evaluateT, schema, ← DatabaseInstance.validSchema]
62+ exact (dbi.relations rn).validSchema t h_t
63+ | s a b sq ih =>
64+ simp_all only [isWellTyped, evaluateT, selectionT, schema]
65+ simp_all only [forall_const, Set.mem_setOf_eq, implies_true]
66+ | p rs sq ih =>
67+ intro t h_t
68+ simp_all [isWellTyped, evaluateT, projectionT, schema]
69+ apply projectionDom ⟨sq.schema dbi.schema, evaluateT dbi sq, ih⟩ ?_ h.2
70+ . simp_all only [projectionT, Set.mem_setOf_eq]
71+ | j sq₁ sq₂ ih₁ ih₂ =>
72+ intro t h_t
73+ simp_all only [isWellTyped, forall_const]
74+ apply joinDom
75+ ⟨sq₁.schema dbi.schema, evaluateT dbi sq₁, ih₁⟩
76+ ⟨sq₂.schema dbi.schema, evaluateT dbi sq₂, ih₂⟩
77+ h_t
78+ | r f sq ih =>
79+ intro t h_t
80+ apply renameDom ⟨sq.schema dbi.schema, evaluateT dbi sq, (by simp_all)⟩ h.2 .2
81+ simp_all only [evaluateT, renameT, Set.mem_setOf_eq]
82+ | u sq₁ sq₂ ih =>
83+ intro _ ht
84+ simp [isWellTyped, evaluateT, unionT, schema] at *
85+ cases ht
86+ all_goals simp_all only
87+ | d sq₁ sq₂ ih =>
88+ intro _ ht
89+ simp [isWellTyped, evaluateT, differenceT, schema] at *
90+ cases ht
91+ all_goals simp_all only
9192
9293/-- Query evaluation for `RelationInstance` -/
9394def Query.evaluate [DecidableEq α] (dbi : DatabaseInstance ρ α μ) (q : Query ρ α) (h : q.isWellTyped dbi.schema) : RelationInstance α μ :=
9495 ⟨
9596 q.schema dbi.schema,
9697 q.evaluateT dbi,
97- by exact fun t a ↦ evaluate.validSchema q h t a
98+ evaluate.validSchema q h
9899 ⟩
99100
100101
@@ -178,4 +179,4 @@ theorem Query.evaluateT.dbi_domain [DecidableEq α] [Nonempty α] {dbi : Databas
178179 | inr ht₂ => exact ih₂ t ht₂
179180
180181 | d q nq ih nih =>
181- simp_all only [isWellTyped, evaluateT, diffT , Set.mem_diff, implies_true]
182+ simp_all only [isWellTyped, evaluateT, differenceT , Set.mem_diff, implies_true]
0 commit comments