Skip to content

Commit 051a016

Browse files
committed
Remove NonEmptyR Assumption
1 parent 8cfbafb commit 051a016

5 files changed

Lines changed: 20 additions & 159 deletions

File tree

RelationalAlgebra/Equivalence/Equivalence.lean

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Requires:
7373
- The value `default : α` is not contained in `brs`
7474
- `default` does not appear in the free variables of the query
7575
- `brs` is disjoint from all relation schemas and all relation schemas are disjoint from the free variables used for that relation
76-
- All relations referenced by the query have nonempty schemas (`FOL.NonemptyR folQ.toFormula`)
7776
-/
7877
section FOLtoRA
7978

@@ -84,19 +83,18 @@ variable {ρ α μ : Type} [Inhabited α] [Inhabited ρ] [LinearOrder α] [Linea
8483

8584
/-- Query evaluation equivalence for `RelationInstance` -/
8685
theorem fol_to_ra_eval (brs_disj : folQ.schema ∩ brs = ∅) (brs_depth : 0 + FOL.depth (toPrenex folQ) < brs.card) (brs_def : default ∉ brs)
87-
(hμ : ∀v, v ∈ dbi.domain) (hdisj : FOL.disjointSchema brs (folQ.toFormula)) (hdef : default ∉ folQ.schema) (hne : FOL.NonemptyR folQ.toFormula) :
86+
(hμ : ∀v, v ∈ dbi.domain) (hdisj : FOL.disjointSchema brs (folQ.toFormula)) (hdef : default ∉ folQ.schema) :
8887
(fol_to_ra_query folQ brs).evaluate dbi (fol_to_ra_query.isWellTyped_def folQ brs_disj brs_depth) = folQ.evaluateAdom dbi := by
8988
simp only [RA.Query.evaluate, FOL.Query.evaluateAdom, RelationInstance.mk.injEq]
9089
apply And.intro
9190
· exact fol_to_ra_query.schema_def folQ
92-
· exact fol_to_ra_query.evalT folQ hμ hdisj hdef hne brs_disj brs_depth brs_def
91+
· exact fol_to_ra_query.evalT folQ hμ hdisj hdef brs_disj brs_depth brs_def
9392

9493
/-- Query expressivity equivalence -/
9594
theorem fol_to_ra (brs : Finset α) (brs_disj : folQ.schema ∩ brs = ∅) (brs_depth : 0 + FOL.depth (toPrenex folQ) < brs.card) (brs_def : default ∉ brs)
96-
(hμ : ∀v, v ∈ dbi.domain) (hdisj : FOL.disjointSchema brs (folQ.toFormula)) (hdef : default ∉ folQ.schema) (hne : FOL.NonemptyR folQ.toFormula) :
95+
(hμ : ∀v, v ∈ dbi.domain) (hdisj : FOL.disjointSchema brs (folQ.toFormula)) (hdef : default ∉ folQ.schema) :
9796
∃raQ : RA.Query _ _, ∃(h' : raQ.isWellTyped dbi.schema), raQ.evaluate dbi h' = folQ.evaluateAdom dbi := by
9897
use fol_to_ra_query folQ brs
9998
use fol_to_ra_query.isWellTyped_def folQ brs_disj brs_depth
100-
exact fol_to_ra_eval folQ brs brs_disj brs_depth brs_def hμ hdisj hdef hne
101-
99+
exact fol_to_ra_eval folQ brs brs_disj brs_depth brs_def hμ hdisj hdef
102100
end FOLtoRA

RelationalAlgebra/Equivalence/FOLtoRA/Adom.lean

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ theorem RA.Query.foldr_union_evalT (xs : List β) (qb : β → RA.Query ρ α) (
5252
def adomRs (dbs : ρ → Finset α) : Set ρ :=
5353
{rn | dbs rn ≠ ∅}
5454

55-
/-- All attributes in the database schema -/
56-
def adomAtts (dbs : ρ → Finset α) : Set α :=
57-
{a | ∃rn, a ∈ dbs rn}
58-
59-
/-- Helper to demonstrate that Fintype adomRs → Fintype adomAtts -/
60-
theorem adomAtts.biUnion_adomRs : ra ∈ adomAtts dbs ↔ ∃rn ∈ adomRs dbs, ra ∈ dbs rn := by
61-
simp [adomRs, adomAtts]
62-
grind
63-
64-
/-- Fintype adomRs → Fintype adomAtts -/
65-
instance {dbs : ρ → Finset α} [Fintype (adomRs dbs)] [DecidableEq α] : Fintype (adomAtts dbs) := by
66-
have : adomAtts dbs = {ra | ∃rn ∈ adomRs dbs, ra ∈ dbs rn} := by
67-
simp [Set.ext_iff, adomAtts.biUnion_adomRs]
68-
rw [this]
69-
apply Fintype.ofFinset ((adomRs dbs).toFinset.biUnion (λ r => dbs r))
70-
simp only [Finset.mem_biUnion, Set.mem_toFinset, Set.mem_setOf_eq, implies_true]
71-
7255

7356
/-- Empty tuple for a relation -/
7457
def EmptyTupleFromRelation (rn : ρ) : RA.Query ρ α :=

RelationalAlgebra/Equivalence/FOLtoRA/NonemptyR.lean

Lines changed: 0 additions & 115 deletions
This file was deleted.

RelationalAlgebra/Equivalence/FOLtoRA/Prenex.lean

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import RelationalAlgebra.Equivalence.FOLtoRA.Adom
22
import RelationalAlgebra.Equivalence.FOLtoRA.Disjoint
33
import RelationalAlgebra.Equivalence.FOLtoRA.FRan
4-
import RelationalAlgebra.Equivalence.FOLtoRA.NonemptyR
54
import RelationalAlgebra.Equivalence.FOLtoRA.Conversion
65
import RelationalAlgebra.FOL.Schema
76
import RelationalAlgebra.FOL.Evaluate
@@ -117,15 +116,15 @@ theorem toRA.isWellTyped_def_IsPrenex [Nonempty ρ] {q : (fol dbs).BoundedFormul
117116

118117
/- Proof that `toRA` evaluation is equivalent to the `Set` of tuples of `RealizeDomSet` for the distinct prenex form cases -/
119118
theorem toRA.evalT_def_IsAtomic [Nonempty ρ] [Inhabited μ] [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n}
120-
(hq : q.IsAtomic) [Fintype (adomRs dbi.schema)] (h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card)
121-
(hdisj : disjointSchema brs q) (hdef : default ∉ rs) (hne : NonemptyR q) :
119+
(hμ : ∀v, v ∈ dbi.domain) (hq : q.IsAtomic) [Fintype (adomRs dbi.schema)] (h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card)
120+
(hdisj : disjointSchema brs q) (hdef : default ∉ rs) :
122121
(toRA q rs brs).evaluateT dbi = RealizeDomSet q rs brs := by
123122
induction hq with
124123
| equal t₁ t₂ => exact equal_def h
125124
| rel R ts =>
126125
cases R with
127126
| R rn =>
128-
apply relToRA.evalT_def h hdef ?_ hne
127+
apply relToRA.evalT_def h hdef ?_
129128

130129
simp [Relations.boundedFormula, disjointSchema, Finset.ext_iff] at hdisj
131130

@@ -150,21 +149,21 @@ theorem toRA.evalT_def_IsAtomic [Nonempty ρ] [Inhabited μ] [Nonempty ↑(adomR
150149

151150
theorem toRA.evalT_def_IsQF [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n}
152151
(hμ : ∀v, v ∈ dbi.domain) (hq : q.IsQF) [Fintype (adomRs dbi.schema)] [Nonempty ↑(adomRs dbi.schema)]
153-
(h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card) (hdisj : disjointSchema brs q) (hdef : default ∉ rs) (hne : NonemptyR q) :
152+
(h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card) (hdisj : disjointSchema brs q) (hdef : default ∉ rs) :
154153
(toRA q rs brs).evaluateT dbi = RealizeDomSet q rs brs := by
155154
induction hq with
156155
| falsum => exact falsum_def
157-
| of_isAtomic h_at => exact toRA.evalT_def_IsAtomic h_at h hn hdisj hdef hne
156+
| of_isAtomic h_at => exact toRA.evalT_def_IsAtomic h_at h hn hdisj hdef
158157

159158
| imp h_qf₁ h_qf₂ ih₁ ih₂ =>
160159
rw [Finset.union_subset_iff, BoundedFormula.freeVarFinset, Finset.union_subset_iff] at h
161160

162161
exact toRA.imp_def hμ
163-
(ih₁ (Finset.union_subset_iff.mpr ⟨h.1.1, h.2⟩) (by simp at hn; grind) (by simp at hdisj; exact ⟨hdisj.1.1, hdisj.2⟩) (hne.1))
164-
(ih₂ (Finset.union_subset_iff.mpr ⟨h.1.2, h.2⟩) (by simp at hn; grind) (by simp at hdisj; exact ⟨hdisj.1.2, hdisj.2⟩) (hne.2))
162+
(ih₁ (Finset.union_subset_iff.mpr ⟨h.1.1, h.2⟩) (by simp at hn; grind) (by simp at hdisj; exact ⟨hdisj.1.1, hdisj.2⟩))
163+
(ih₂ (Finset.union_subset_iff.mpr ⟨h.1.2, h.2⟩) (by simp at hn; grind) (by simp at hdisj; exact ⟨hdisj.1.2, hdisj.2⟩))
165164

166165
theorem toRA.evalT_def_IsPrenex [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n} [Fintype (adomRs dbi.schema)] [Nonempty ↑(adomRs dbi.schema)]
167-
(hμ : ∀v, v ∈ dbi.domain) (hq : q.IsPrenex) (h' : brs ∩ q.freeVarFinset = ∅) (hn : n + depth q < brs.card) (hdisj : disjointSchema brs q) (hdef : default ∉ q.freeVarFinset ∪ brs) (hne : NonemptyR q) :
166+
(hμ : ∀v, v ∈ dbi.domain) (hq : q.IsPrenex) (h' : brs ∩ q.freeVarFinset = ∅) (hn : n + depth q < brs.card) (hdisj : disjointSchema brs q) (hdef : default ∉ q.freeVarFinset ∪ brs) :
168167
(toRA q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs).evaluateT dbi = RealizeDomSet q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs := by
169168
induction hq with
170169
| of_isQF hqf =>
@@ -173,14 +172,14 @@ theorem toRA.evalT_def_IsPrenex [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q :
173172
simp at ⊢ hdef;
174173
apply And.intro hdef.1 (FreeMap.notMem_notMem_FRan ?_ hdef.2)
175174
grind
176-
exact evalT_def_IsQF hμ hqf (fun ⦃a⦄ a ↦ a) hn hdisj hdef' hne
175+
exact evalT_def_IsQF hμ hqf (fun ⦃a⦄ a ↦ a) hn hdisj hdef'
177176

178177
| all hφ ih =>
179178
apply all_def hμ (by grind) ?_
180179

181180
. simp [← Nat.add_assoc] at hn
182181

183-
exact ih h' hn hdisj hdef hne
182+
exact ih h' hn hdisj hdef
184183

185184
. simp [Finset.eq_empty_iff_forall_notMem] at h'
186185
apply h'
@@ -200,10 +199,10 @@ theorem toRA.evalT_def_IsPrenex [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q :
200199

201200
. rw [helper φ]
202201
simp_rw [BoundedFormula.freeVarFinset, Finset.union_empty] at h' ⊢ hdef
203-
simp at hdisj hne
202+
simp at hdisj
204203
simp [← Nat.add_assoc] at hn
205204

206-
exact ih h' hn hdisj hdef hne
205+
exact ih h' hn hdisj hdef
207206

208207
. simp [Finset.eq_empty_iff_forall_notMem] at h'
209208
simp
@@ -235,7 +234,7 @@ theorem fol_to_ra_query.isWellTyped_def [Nonempty ρ] (q : FOL.Query dbs) [Finty
235234

236235
/-- Conversion evaluation `Set` tuples equivalence proof (all tuples are restricted to `DatabaseInstance.domain`) -/
237236
theorem fol_to_ra_query.evalT [folStruc dbi] [Fintype (adomRs dbi.schema)] [Nonempty ↑(adomRs dbi.schema)] [Inhabited μ] [Nonempty ρ]
238-
(q : FOL.Query dbi.schema) (hμ : ∀v, v ∈ dbi.domain) (hdisj : disjointSchema brs q.toFormula) (hdef : default ∉ q.schema) (hne : NonemptyR q.toFormula)
237+
(q : FOL.Query dbi.schema) (hμ : ∀v, v ∈ dbi.domain) (hdisj : disjointSchema brs q.toFormula) (hdef : default ∉ q.schema)
239238
(hbrs : q.schema ∩ brs = ∅) (hdepth : 0 + depth (toPrenex q) < brs.card) (hdef' : default ∉ brs) :
240239
RA.Query.evaluateT dbi (fol_to_ra_query q brs) = FOL.Query.evaluateT dbi q ∩ {t | t.ran ⊆ dbi.domain} := by
241240
rw [FOL.Query.evaluateT, Set.ext_iff]
@@ -248,7 +247,7 @@ theorem fol_to_ra_query.evalT [folStruc dbi] [Fintype (adomRs dbi.schema)] [None
248247
have hq := BoundedFormula.toPrenex_isPrenex (BoundedQuery.toFormula q)
249248
have helper : (BoundedQuery.toFormula q).toPrenex.freeVarFinset ∪ FRan (FreeMap 0 brs)
250249
= (BoundedQuery.toFormula q).toPrenex.freeVarFinset := by simp [FRan]
251-
rw [← freeVarFinset_toPrenex, ← helper, toRA.evalT_def_IsPrenex hμ hq ?_ ?_ ?_ ?_ ?_]
250+
rw [← freeVarFinset_toPrenex, ← helper, toRA.evalT_def_IsPrenex hμ hq ?_ ?_ ?_ ?_]
252251

253252
rw [Set.mem_setOf_eq]
254253
simp only [BoundedFormula.realize_toPrenex, RealizeDomSet]
@@ -263,4 +262,3 @@ theorem fol_to_ra_query.evalT [folStruc dbi] [Fintype (adomRs dbi.schema)] [None
263262
. exact ⟨(disjointSchemaL.toPrenex (BoundedQuery.toFormula q)).mpr hdisj.1, hdisj.2
264263
. simp only [freeVarFinset_toPrenex, Finset.mem_union, not_or]
265264
exact ⟨hdef, hdef'⟩
266-
. exact (NonemptyR.toPrenex (BoundedQuery.toFormula q)).mpr hne

RelationalAlgebra/Equivalence/FOLtoRA/Relation.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ theorem relToRA.isWellTyped_def [Nonempty ↑(adomRs dbs)] {ts : Fin (dbs rn).ca
883883
simp [relToRA, relJoinsMin.isWellTyped_def, adom.isWellTyped_def, adom.schema_def]
884884

885885
theorem relToRA.evalT_def {dbi : DatabaseInstance ρ α μ} [Nonempty (adomRs dbi.schema)] [Fintype (adomRs dbi.schema)] [folStruc dbi] [Inhabited μ] {ts : Fin (dbi.schema rn).card → (fol dbi.schema).Term (α ⊕ Fin n)}
886-
(hrs : (Finset.univ.biUnion fun i ↦ (ts i).varFinsetLeft) ∪ FRan (FreeMap n brs) ⊆ rs) (hu : default ∉ rs) (hdisj : (dbi.schema rn) ∩ (dbi.schema rn).image (renamer ts brs) = ∅) (hne : dbi.schema rn ≠ ∅) :
886+
(hrs : (Finset.univ.biUnion fun i ↦ (ts i).varFinsetLeft) ∪ FRan (FreeMap n brs) ⊆ rs) (hu : default ∉ rs) (hdisj : (dbi.schema rn) ∩ (dbi.schema rn).image (renamer ts brs) = ∅) ( : ∀ (v : μ), v ∈ dbi.domain) :
887887
RA.Query.evaluateT dbi (relToRA ts rs brs) = RealizeDomSet (Relations.boundedFormula (relations.R rn) ts) rs brs := by
888888
simp_rw [RealizeDomSet, BoundedFormula.realize_rel]
889889
simp_rw [folStruc_apply_RelMap, ArityToTuple.def_dite, exists_and_right]
@@ -997,9 +997,6 @@ theorem relToRA.evalT_def {dbi : DatabaseInstance ρ α μ} [Nonempty (adomRs db
997997
. use t
998998
apply And.intro
999999
. simp [w_1, right]
1000-
use rn
1001-
apply And.intro
1002-
. simp [adomRs, hne]
1003-
. use t ∘ renamer ts brs
1000+
apply adom.exists_tuple_from_value hμ
10041001
. exact joinSingleT.restrict t
10051002
. simp [Part.eq_none_iff', Part.dom_iff_mem, ← PFun.mem_dom, w_1]

0 commit comments

Comments
 (0)