Skip to content

Commit f4cb19e

Browse files
committed
Simplified FOL Relation Implementation
1 parent dfdd4d4 commit f4cb19e

5 files changed

Lines changed: 11 additions & 18 deletions

File tree

RelationalAlgebra/Equivalence/FOLtoRA/Relation.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,6 @@ theorem relToRA.evalT_def {dbi : DatabaseInstance ρ α μ} [Nonempty (adomRs db
887887
RA.Query.evaluateT dbi (relToRA ts rs brs) =
888888
{t | ∃h, RealizeDomSet (μ := μ) (Relations.boundedFormula (relations.R rn) ts) rs brs t h} := by
889889
simp_rw [RealizeDomSet, BoundedFormula.realize_rel]
890-
rw [← fol.Rel]
891890
simp_rw [folStruc_apply_RelMap, ArityToTuple.def_dite, exists_and_right]
892891

893892
have h₁ : ∀ (i : Fin (dbi.schema rn).card), TermtoAtt brs (ts i) ∈ rs := by

RelationalAlgebra/Equivalence/RAtoFOL/Relation.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ theorem ra_to_fol_evalT.R_def.mp :
77
∀t, (ra_to_fol_query dbi.schema (.R rn)).RealizeMin dbi t → t ∈ RA.Query.evaluateT dbi (.R rn) := by
88
intro t
99
simp_all only [FOL.Query.RealizeMin, FOL.BoundedQuery.Realize, ra_to_fol_query,
10-
FOL.BoundedQuery.toFormula.eq_1, FOL.fol.Rel,
11-
FirstOrder.Language.BoundedFormula.realize_rel, Function.comp_apply, FOL.outVar.def,
12-
FirstOrder.Language.Term.realize_var, Sum.elim_inl, FOL.BoundedQuery.schema.R_def,
13-
FirstOrder.Language.Term.varFinsetLeft.eq_1, Finset.mem_singleton,
14-
RM.RelationSchema.Dom_sub_fromIndex, Finset.toFinset_coe, RA.Query.evaluateT,
15-
forall_exists_index]
10+
FOL.BoundedQuery.toFormula.eq_1, FirstOrder.Language.BoundedFormula.realize_rel,
11+
Function.comp_apply, FOL.outVar.def, FirstOrder.Language.Term.realize_var, Sum.elim_inl,
12+
FOL.BoundedQuery.schema.R_def, FirstOrder.Language.Term.varFinsetLeft.eq_1,
13+
Finset.mem_singleton, RM.RelationSchema.Dom_sub_fromIndex, Finset.toFinset_coe,
14+
RA.Query.evaluateT, forall_exists_index]
1615
intro h a_1
1716
rw [@FOL.folStruc.RelMap_R] at a_1
1817
convert a_1

RelationalAlgebra/FOL/ModelTheory.lean

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ def Language.fol (dbs : ρ → Finset α) : Language :=
115115
Relations := relations dbs }
116116
deriving Language.IsRelational
117117

118-
@[simp]
119-
def fol.Rel {dbs: ρ → Finset α} (rn: ρ) : (Language.fol dbs).Relations (dbs rn).card :=
120-
relations.R rn
121-
122-
123118
open Language
124119

125120
section struc
@@ -142,8 +137,8 @@ class folStruc (dbi : DatabaseInstance ρ α μ) extends (fol dbi.schema).Struct
142137
)
143138

144139
@[simp]
145-
theorem folStruc_apply_RelMap (dbi : DatabaseInstance ρ α μ) [folStruc dbi] {rn} {va : Fin (dbi.schema rn).card → μ} :
146-
Structure.RelMap (fol.Rel rn) va ↔ ArityToTuple va ∈ (dbi.relations rn).tuples
140+
theorem folStruc_apply_RelMap (dbi : DatabaseInstance ρ α μ) [s : folStruc dbi] {rn} {va : Fin (dbi.schema rn).card → μ} :
141+
s.RelMap (.R rn) va ↔ ArityToTuple va ∈ (dbi.relations rn).tuples
147142
:= (folStruc.RelMap_R rn va)
148143

149144
@[simp]

RelationalAlgebra/FOL/Query.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def BoundedQuery.exs : ∀ {n}, BoundedQuery dbs n → Query dbs
3434
/-- `BoundedQuery` conversion to `BoundedFormula`. -/
3535
@[simp]
3636
def BoundedQuery.toFormula : (q : BoundedQuery dbs n) → (fol dbs).BoundedFormula α n
37-
| .R name vMap => Relations.boundedFormula (fol.Rel name) vMap
37+
| .R name vMap => Relations.boundedFormula (.R name) vMap
3838
| .tEq t₁ t₂ => .equal t₁ t₂
3939
| .and q1 q2 => q1.toFormula ⊓ q2.toFormula
4040
| .ex q => .ex q.toFormula

RelationalAlgebra/FOL/RealizeProperties.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ theorem BoundedFormula.Realize.equiv [folStruc dbi] {q : (fol dbi.schema).Bounde
1616
next rn =>
1717
simp at ht
1818
rw [BoundedFormula.Realize, BoundedFormula.Realize]
19-
rw [← fol.Rel, folStruc_apply_RelMap, folStruc_apply_RelMap]
19+
rw [folStruc_apply_RelMap, folStruc_apply_RelMap]
2020
have : (fun i ↦ realize (Sum.elim t₁ iv₁) (ts i)) = (fun i ↦ realize (Sum.elim t₂ iv₂) (ts i)) := by
2121
ext i
2222
have ⟨k, hk⟩ := Term.cases (ts i)
@@ -78,7 +78,7 @@ theorem BoundedQuery.Realize.enlarge [folStruc dbi] {rs rs' : Finset α} {tup tu
7878
: q.Realize dbi (TupleToFun h'.symm) iv ↔ q.Realize dbi (TupleToFun h.symm) iv := by
7979
induction q with
8080
| R rn vMap =>
81-
simp only [Realize, toFormula, fol.Rel, BoundedFormula.realize_rel, folStruc.RelMap_R,
81+
simp only [Realize, toFormula, BoundedFormula.realize_rel, folStruc.RelMap_R,
8282
ArityToTuple.def_dite]
8383
rw [@iff_eq_eq]
8484
apply congr rfl
@@ -225,7 +225,7 @@ theorem BoundedQuery.Realize.restrict [folStruc dbi] {rs : Finset α} {q : Bound
225225

226226
induction q with
227227
| R rn ts =>
228-
simp_all only [toFormula, fol.Rel, BoundedFormula.realize_rel]
228+
simp_all only [toFormula, BoundedFormula.realize_rel]
229229
simp only [folStruc.RelMap_R, iff_eq_eq]
230230
apply congr rfl
231231
ext a v

0 commit comments

Comments
 (0)