Skip to content

Commit aef2fcb

Browse files
committed
Removed Unused Files & Minor Refactoring
1 parent 45fa74f commit aef2fcb

12 files changed

Lines changed: 24 additions & 296 deletions

File tree

Design.md

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

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,17 @@ Relational Algebra (RA) is the theoretical foundation of SQL and a cornerstone o
88

99
This project formalizes:
1010

11-
- The core constructs of Relational Algebra (e.g. selection, projection, join, union, difference, renaming).
11+
- The core constructs of Relational Algebra (i.e. selection, projection, join, renaming, union, difference).
1212
- A corresponding fragment of First-Order Logic with active domain semantics.
1313
- The expressive equivalence between RA and FOL under this interpretation.
1414

1515
The formalization is developed in [Lean 4](https://leanprover.github.io), using its dependent type theory framework and the [mathlib4](https://github.com/leanprover-community/mathlib4) library where possible.
1616

1717
## ✅ Goals
1818

19-
- ✅ Formalize SPJR algebra.
20-
- ✅ Formalize SPJRU algebra.
21-
- ✅ Formalize complete relational algebra.
19+
- ✅ Formalize relational algebra.
2220
- ✅ Formalize equivalent fragments of FOL.
2321
- ✅ Prove equivalence theorems between RA and FOL expressions.
2422
- 🔄 Ensure reusable and well-documented Lean definitions.
2523

26-
## 🧠 Design Rationale
27-
28-
The design decisions behind the formalization — such as how tuples, schemas, and relational operations are represented in Lean — are documented in the [`Design.md`](./Design.md) file. This includes:
29-
30-
- Key trade-offs (e.g., bundled vs. unbundled representations)
31-
- Justification for using partial functions and specific Lean constructs
32-
33-
Reading `Design.md` is recommended if you're contributing to the codebase or want to understand the reasoning behind implementation choices.
34-
3524
---

RelationalAlgebra/Equivalence/FOLtoRA/Conversion.lean

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import RelationalAlgebra.Equivalence.FOLtoRA.Adom
2-
import RelationalAlgebra.Equivalence.FOLtoRA.FreshAtts
32
import RelationalAlgebra.Equivalence.FOLtoRA.FRan
43
import RelationalAlgebra.Equivalence.FOLtoRA.Relation
54
import RelationalAlgebra.Equivalence.FOLtoRA.Term
@@ -91,15 +90,15 @@ variable [Inhabited ρ] [LinearOrder ρ]
9190
/- Proof `toRA` evaluation for `Set` of tuples to be equivalent to `RealizeDomSet` for the distinct cases -/
9291
theorem toRA.falsum_def [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)] [Fintype ↑(adomRs dbi.schema)] :
9392
(toRA (BoundedFormula.falsum (L := fol dbi.schema) (n := n)) rs brs).evaluateT dbi =
94-
{t | ∃h, RealizeDomSet (BoundedFormula.falsum (L := fol dbi.schema) (n := n)) rs brs t h} := by
93+
RealizeDomSet (BoundedFormula.falsum (L := fol dbi.schema) (n := n)) rs brs := by
9594
have : (RA.Query.evaluateT dbi (adom dbi.schema rs)) \ (RA.Query.evaluateT dbi (adom dbi.schema rs)) = ∅ := Set.diff_self
9695
simp_rw [toRA, RA.Query.evaluateT, differenceT, this]
9796
simp [RealizeDomSet, BoundedFormula.Realize]
9897

9998

10099
theorem toRA.equal_def [Nonempty ↑(adomRs dbi.schema)] [Fintype ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)] {t₁ t₂ : (fol dbi.schema).Term (α ⊕ Fin n)}
101100
(h : (t₁ =' t₂).freeVarFinset ∪ FRan (FreeMap n brs) ⊆ rs) :
102-
(toRA (t₁ =' t₂) rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet (t₁ =' t₂) rs brs t h} := by
101+
(toRA (t₁ =' t₂) rs brs).evaluateT dbi = RealizeDomSet (t₁ =' t₂) rs brs := by
103102
simp_rw [Term.bdEqual, toRA, RA.Query.evaluateT, selectionT]
104103
simp_rw [RealizeDomSet]
105104

@@ -146,9 +145,9 @@ theorem toRA.equal_def [Nonempty ↑(adomRs dbi.schema)] [Fintype ↑(adomRs dbi
146145

147146
theorem toRA.imp_def [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)] [Fintype ↑(adomRs dbi.schema)]
148147
(hμ : ∀v : μ, v ∈ dbi.domain)
149-
(ih₁ : (toRA (dbs := dbi.schema) q₁ rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet q₁ rs brs t h})
150-
(ih₂ : (toRA (dbs := dbi.schema) q₂ rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet q₂ rs brs t h}) :
151-
(toRA (q₁.imp q₂) rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet (q₁.imp q₂) rs brs t h} := by
148+
(ih₁ : (toRA (dbs := dbi.schema) q₁ rs brs).evaluateT dbi = RealizeDomSet q₁ rs brs)
149+
(ih₂ : (toRA (dbs := dbi.schema) q₂ rs brs).evaluateT dbi = RealizeDomSet q₂ rs brs) :
150+
(toRA (q₁.imp q₂) rs brs).evaluateT dbi = RealizeDomSet (q₁.imp q₂) rs brs := by
152151
ext t
153152
simp only [toRA, RA.Query.evaluateT, differenceT, adom.complete_def, Set.mem_diff, Set.mem_setOf_eq,
154153
not_and, not_not, RealizeDomSet, BoundedFormula.realize_imp, exists_and_right]
@@ -157,21 +156,21 @@ theorem toRA.imp_def [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)]
157156
TupleToFun.tuple_eq_self]
158157
apply Iff.intro
159158
· intro a_1
160-
simp_all only [Finset.coe_inj, TupleToFun.tuple_eq_self, implies_true, exists_const, and_self]
159+
simp_all only [implies_true, exists_const, and_self]
161160
· intro ⟨⟨w_1, h_1⟩, right⟩
162161
simp_all [Finset.coe_inj, TupleToFun.tuple_eq_self, implies_true, and_self]
163162
apply adom.exists_tuple_from_value hμ
164163

165164
theorem toRA.not_def [Nonempty ↑(adomRs dbi.schema)] [Fintype ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)]
166165
(hμ : ∀v : μ, v ∈ dbi.domain)
167-
(ih : (toRA (dbs := dbi.schema) q rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet q rs brs t h}) :
168-
(toRA q.not rs brs).evaluateT dbi = {t | ∃h, RealizeDomSet (q.not) rs brs t h} := by
166+
(ih : (toRA (dbs := dbi.schema) q rs brs).evaluateT dbi = RealizeDomSet q rs brs) :
167+
(toRA q.not rs brs).evaluateT dbi = RealizeDomSet (q.not) rs brs := by
169168
exact imp_def hμ ih falsum_def
170169

171170
theorem toRA.all_def [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi (μ := μ)] [Fintype ↑(adomRs dbi.schema)] {q : (fol dbi.schema).BoundedFormula α (n + 1)}
172171
(hμ : ∀v : μ, v ∈ dbi.domain) (hn : n + depth (∀'q) < brs.card) (h : (FreeMap (n + 1) brs) (Fin.last n) ∉ q.freeVarFinset)
173-
(ih : (toRA q (q.freeVarFinset ∪ FRan (FreeMap (n + 1) brs)) brs).evaluateT dbi = {t | ∃h, RealizeDomSet q (q.freeVarFinset ∪ FRan (FreeMap (n + 1) brs)) brs t h}) :
174-
(toRA q.all (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs).evaluateT dbi = {t | ∃h, RealizeDomSet (q.all) (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs t h} := by
172+
(ih : (toRA q (q.freeVarFinset ∪ FRan (FreeMap (n + 1) brs)) brs).evaluateT dbi = RealizeDomSet q (q.freeVarFinset ∪ FRan (FreeMap (n + 1) brs)) brs) :
173+
(toRA q.all (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs).evaluateT dbi = RealizeDomSet (q.all) (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs := by
175174
simp only [toRA, RA.Query.evaluateT, Finset.union_assoc, differenceT]
176175
rw [FreeMap.FRan_union_add_one (by grind), ih]
177176

RelationalAlgebra/Equivalence/FOLtoRA/Disjoint.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import RelationalAlgebra.Equivalence.FOLtoRA.FRan
2-
import RelationalAlgebra.Equivalence.FOLtoRA.FreshAtts
32
import RelationalAlgebra.FOL.ModelTheoryExtensions
43

54
/-
65
To simplify the conversion and proof, we decided to allow for the assumption that the attributes used to represent the bound variables (`brs`)
76
is disjoint from the named attributes used in any of the relations AND there is no intersection between free variables and relation attributes used in the query.
8-
This assumption is a short-cut, given we use `FreshAtts` to generate `brs` which avoids these variables.
9-
However, due to deadlines we decided to leave this proof as future work.
7+
This assumption simplifies the proof without real loss of generality, since in practice renaming of attributes/variables could resolve the issues that would occur.
108
-/
119

1210
open FOL FirstOrder Language Term RM

RelationalAlgebra/Equivalence/FOLtoRA/FreshAtts.lean

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

RelationalAlgebra/Equivalence/FOLtoRA/NonemptyR.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import RelationalAlgebra.Equivalence.FOLtoRA.FRan
2-
import RelationalAlgebra.Equivalence.FOLtoRA.FreshAtts
32
import RelationalAlgebra.FOL.ModelTheoryExtensions
43

54
/-

RelationalAlgebra/Equivalence/FOLtoRA/Prenex.lean

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import RelationalAlgebra.Equivalence.FOLtoRA.Adom
22
import RelationalAlgebra.Equivalence.FOLtoRA.Disjoint
3-
import RelationalAlgebra.Equivalence.FOLtoRA.FreshAtts
43
import RelationalAlgebra.Equivalence.FOLtoRA.FRan
54
import RelationalAlgebra.Equivalence.FOLtoRA.NonemptyR
65
import RelationalAlgebra.Equivalence.FOLtoRA.Conversion
@@ -116,12 +115,11 @@ theorem toRA.isWellTyped_def_IsPrenex [Nonempty ρ] {q : (fol dbs).BoundedFormul
116115
simp only [adom.isWellTyped_def, adom.schema_def, toRA.schema_def, true_and, and_true, *]
117116
exact Finset.union_subset_union_right (FreeMap.FRan_sub_add_one (by grind))
118117

119-
/- Proof that `toRA` evaluation is equivalent to the `Set` of tuples satisfying `RealizeDomSet` for the distinct prenex form cases -/
118+
/- Proof that `toRA` evaluation is equivalent to the `Set` of tuples of `RealizeDomSet` for the distinct prenex form cases -/
120119
theorem toRA.evalT_def_IsAtomic [Nonempty ρ] [Inhabited μ] [Nonempty ↑(adomRs dbi.schema)] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n}
121120
(hq : q.IsAtomic) [Fintype (adomRs dbi.schema)] (h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card)
122121
(hdisj : disjointSchema brs q) (hdef : default ∉ rs) (hne : NonemptyR q) :
123-
(toRA q rs brs).evaluateT dbi =
124-
{t | ∃h, RealizeDomSet q rs brs t h} := by
122+
(toRA q rs brs).evaluateT dbi = RealizeDomSet q rs brs := by
125123
induction hq with
126124
| equal t₁ t₂ => exact equal_def h
127125
| rel R ts =>
@@ -153,8 +151,7 @@ theorem toRA.evalT_def_IsAtomic [Nonempty ρ] [Inhabited μ] [Nonempty ↑(adomR
153151
theorem toRA.evalT_def_IsQF [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n}
154152
(hμ : ∀v, v ∈ dbi.domain) (hq : q.IsQF) [Fintype (adomRs dbi.schema)] [Nonempty ↑(adomRs dbi.schema)]
155153
(h : (q.freeVarFinset ∪ FRan (FreeMap n brs)) ⊆ rs) (hn : n + depth q < brs.card) (hdisj : disjointSchema brs q) (hdef : default ∉ rs) (hne : NonemptyR q) :
156-
(toRA q rs brs).evaluateT dbi =
157-
{t | ∃h, RealizeDomSet q rs brs t h} := by
154+
(toRA q rs brs).evaluateT dbi = RealizeDomSet q rs brs := by
158155
induction hq with
159156
| falsum => exact falsum_def
160157
| of_isAtomic h_at => exact toRA.evalT_def_IsAtomic h_at h hn hdisj hdef hne
@@ -168,8 +165,7 @@ theorem toRA.evalT_def_IsQF [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q : (fo
168165

169166
theorem toRA.evalT_def_IsPrenex [Nonempty ρ] [Inhabited μ] [folStruc dbi] {q : (fol dbi.schema).BoundedFormula α n} [Fintype (adomRs dbi.schema)] [Nonempty ↑(adomRs dbi.schema)]
170167
(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) :
171-
(toRA q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs).evaluateT dbi =
172-
{t | ∃h, RealizeDomSet q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs t h} := by
168+
(toRA q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs).evaluateT dbi = RealizeDomSet q (q.freeVarFinset ∪ FRan (FreeMap n brs)) brs := by
173169
induction hq with
174170
| of_isQF hqf =>
175171
rename_i n' q

RelationalAlgebra/Equivalence/FOLtoRA/RealizeDomSet.lean

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import RelationalAlgebra.Equivalence.FOLtoRA.FRan
44
open RM FOL FirstOrder Language
55

66
/--
7-
Whether a `BoundedFormula` is satisfied by a tuple `t` given `t.Dom = rs`
8-
AND whether all values of `t` are part of the active domain.
7+
The set of tuples (`t : α →. μ`) satisfying a `BoundedFormula` with given `t.Dom = rs` and `t.ran ⊆ dbi.domain`.
98
-/
109
@[simp]
1110
def RealizeDomSet {dbi : DatabaseInstance ρ α μ} [LinearOrder α] [Inhabited α] [folStruc dbi] [Inhabited μ]
12-
(q : (fol dbi.schema).BoundedFormula α n) (rs brs : Finset α) (t : α →. μ) (h : t.Dom = rs) : Prop :=
13-
q.Realize (TupleToFun h) (TupleToFun h ∘ FreeMap n brs) ∧ t.ran ⊆ dbi.domain
11+
(q : (fol dbi.schema).BoundedFormula α n) (rs brs : Finset α) : Set (α →. μ) :=
12+
{t : α →. μ | ∃h : t.Dom = rs, q.Realize (TupleToFun h) (TupleToFun h ∘ FreeMap n brs) ∧ t.ran ⊆ dbi.domain}

0 commit comments

Comments
 (0)