Skip to content

Commit 49ea525

Browse files
committed
...
0 parents  commit 49ea525

10 files changed

Lines changed: 451 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lean Action CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: leanprover/lean-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.lake

Main.lean

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
import Mathlib
2+
import Auto
3+
import Smt
4+
5+
import Mathlib.Probability.Distributions.Uniform
6+
import Mathlib.Data.Real.Basic
7+
import Mathlib.Data.Real.Sqrt
8+
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Defs
9+
import Mathlib.Data.Finset.BooleanAlgebra
10+
import Mathlib
11+
12+
/-!
13+
# Definitions and Theorems about Proximity Gaps
14+
15+
We define the proximity gap properties of linear codes over finite fields.
16+
17+
## Main Definitions
18+
19+
-/
20+
21+
open NNReal Finset Function
22+
23+
open scoped BigOperators
24+
25+
variable {n : Type*} [Fintype n] [DecidableEq n]
26+
27+
variable {F : Type*} [Field F] [Fintype F] [DecidableEq F]
28+
29+
variable (C : Submodule F (n → F)) [DecidablePred (· ∈ C)]
30+
31+
/-- The proximity measure of two vectors `u` and `v` from a code `C` at distance `d` is the number
32+
of vectors at distance at most `d` from the linear combination of `u` and `v` with coefficients
33+
`r` in `F`. -/
34+
def proximityMeasure (u v : n → F) (d : ℕ) : ℕ :=
35+
Fintype.card {r : F | Δ₀'(r • u + (1 - r) • v, C) ≤ d}
36+
37+
/-- A code `C` exhibits proximity gap at distance `d` and cardinality bound `bound` if for every
38+
pair of vectors `u` and `v`, whenever the proximity measure for `C u v d` is greater than
39+
`bound`, then the distance of `[u | v]` from the interleaved code `C ^⊗ 2` is at most `d`. -/
40+
def proximityGap (d : ℕ) (bound : ℕ) : Prop :=
41+
∀ u v : n → F, (proximityMeasure C u v d > bound)
42+
→ (Δ₀( u ⋈ v , C ^⋈ Fin 2 ) ≤ d)
43+
44+
/-- A code `C` exhibits `δ`-correlated agreement with respect to a tuple of vectors `W_1, ..., W_k`
45+
if there exists a set `S` of coordinates such that the size of `S` is at least `(1 - δ) * |n|`,
46+
and there exists a tuple of codewords `v_1, ..., v_k` such that `v_i` agrees with `W_i` on `S`
47+
for all `i`. -/
48+
def correlatedAgreement (C : Set (n → F)) (δ : ℝ≥0) {k : ℕ} (W : Fin k → n → F) : Prop :=
49+
∃ S : Finset n, #(S) ≥ (1 - δ) * (Fintype.card n) ∧
50+
∃ v : Fin k → n → F, ∀ i, v i ∈ C ∧ {j | v i j = W i j} ⊆ S
51+
52+
53+
section
54+
55+
variable {α : Type*}[DecidableEq α] [Nonempty α]
56+
{ι : Type*} [DecidableEq ι] [Nonempty ι]
57+
58+
59+
/--
60+
Distance from a point to a set of points.
61+
-/
62+
noncomputable def distToSet (Δ : (ι → α) → (ι → α) → ℝ≥0) (x : ι → α) (P : Set (ι → α)) : ℝ≥0 :=
63+
sInf {d | ∃ y ∈ P, Δ x y = d}
64+
65+
66+
/--
67+
Definition 1.1 in Proximity Gaps paper.
68+
KATY TO DO: maybe `δ : ℝ≥0` to reflect the rel distances?
69+
Here, `S` can be empty. Maybe add a condition for every S non-empty, then blah
70+
-/
71+
noncomputable def generalProximityGap (P : Finset (ι → α)) (C : Finset (Finset (ι → α)))
72+
(Δ : (ι → α) → (ι → α) → ℕ) (δ ε : ℝ≥0) (S : Finset (ι → α)) (h' : S ∈ C) (h : S.Nonempty)
73+
: Prop :=
74+
(PMF.uniformOfFinset S h).toOuterMeasure {x | distToSet Δ x P ≤ δ} = 1
75+
∨ (PMF.uniformOfFinset S h).toOuterMeasure {x | distToSet Δ x P ≤ δ} ≤ ε
76+
77+
78+
-- noncomputable def setOfSubmodules [Field F] : Set (Submodule F (ι → F)) :=
79+
--{A | ∃ B : Submodule F (ι → F), A = B}
80+
-- Set.univ
81+
82+
83+
lemma setOfSubmodules_nonempty :
84+
{A | ∃ B : Submodule F (ι → F), A = B}.Nonempty := by simp only [exists_eq', Set.setOf_true,
85+
Set.univ_nonempty]
86+
87+
lemma setOfSubmodules_finite [Fintype F] [Fintype ι] :
88+
{A | ∃ B : Submodule F (ι → F), A = B}.Finite := by
89+
simp only [exists_eq', Set.setOf_true]
90+
exact Set.finite_univ
91+
92+
-- Fintype.ofFinite
93+
94+
#print AffineSubspace
95+
96+
-- noncomputable def setOfAffineSubspaces [Field F] : Set (AffineSubspace F (ι → F)) :=
97+
-- {A | ∃ B : AffineSubspace F (ι → F), A = B}
98+
99+
100+
lemma setOfAffineSubspaces_nonempty :
101+
{A | ∃ B : AffineSubspace F (ι → F), A = B}.Nonempty := by simp only [exists_eq', Set.setOf_true,
102+
Set.univ_nonempty]
103+
104+
lemma setOfAffineSubspaces_finite [Fintype F] [Fintype ι] :
105+
{A | ∃ B : AffineSubspace F (ι → F), A = B}.Finite := by
106+
simp only [exists_eq', Set.setOf_true]
107+
exact Set.finite_univ
108+
109+
noncomputable def proximityParams [Fintype F] [Fintype ι] (δ : ℝ≥0) (deg : ℕ)
110+
(domain : ι ↪ F) : ℝ≥0 :=
111+
if UD : δ ≤ 1 - (ReedSolomonCode.sqrtRate deg domain)/2 then Fintype.card ι / Fintype.card F
112+
else if JB : δ ≥ 1 - (ReedSolomonCode.sqrtRate deg domain)/2 ∧ δ ≤ 1 -
113+
(ReedSolomonCode.sqrtRate deg domain)
114+
then
115+
let m := min (1 - (ReedSolomonCode.sqrtRate deg domain) - δ)
116+
(ReedSolomonCode.sqrtRate deg domain/ 20)
117+
⟨(deg ^ 2 : ℝ≥0) / ((2 * m) ^ 7 * (Fintype.card F : ℝ)), by positivity⟩
118+
else 0
119+
120+
-- /--
121+
-- Theorem 1.2 (Proximity gap for RS codes)
122+
-- -/
123+
-- theorem proximityGapsRSCode [Fintype ι] [Nonempty ι] [Field F] [Fintype F]
124+
125+
/--
126+
Theorem 1.4 (Main Theorem — Correlated agreement over lines) in Proximity Gaps
127+
-/
128+
theorem correlatedAgreement_lines [Fintype ι] [Nonempty ι] [Field F] [Fintype F]
129+
(u : Fin 2 → ι → F) (δ : ℝ≥0) (deg : ℕ) (domain : ι ↪ F)
130+
(hδ : δ ≤ 1 - (ReedSolomonCode.sqrtRate deg domain))
131+
(hproximity : (PMF.uniformOfFintype F).toOuterMeasure
132+
{z | Code.relHammingDistToCode (u 1 + z • u 2) (ReedSolomon.code domain deg) ≤ δ}
133+
> proximityParams δ deg domain) :
134+
correlatedAgreement (ReedSolomon.code domain deg) δ u := by sorry
135+
136+
/--
137+
Let `u := {u_1, ..., u_l}` be a collection of vectors in `F^ι`. The parameterised curve of degree
138+
`l` generated by `u` is the set of linear combinations of the form `{∑ i ∈ l r ^ i • u_i | r ∈ F}`.
139+
-/
140+
def parametrisedCurve {l : ℕ} (u : Fin l → ι → F) : Set (ι → F) :=
141+
{v | ∃ r : F, v = ∑ i : Fin l, (r ^ (i : ℕ)) • u i}
142+
143+
/--
144+
A parametrised curve over a finite field.
145+
-/
146+
def parametrisedCurve' [Fintype ι] [Field F] [Fintype F] {l : ℕ} (u : Fin l → ι → F) :
147+
Finset (ι → F) := {v | ∃ r : F, v = ∑ i : Fin l, (r ^ (i : ℕ)) • u i}
148+
149+
150+
instance [Fintype ι] [Field F] [Fintype F] [Nonempty F] {l : ℕ} :
151+
∀ u : Fin l → ι → F, Nonempty {x // x ∈ parametrisedCurve' u } := by
152+
intro u
153+
unfold parametrisedCurve'
154+
simp only [mem_filter, mem_univ, true_and, nonempty_subtype]
155+
obtain ⟨r⟩ := ‹Nonempty F›
156+
use ∑ i : Fin l, r ^ (i : ℕ) • u i, r
157+
158+
159+
/--
160+
Theorem 1.5 (Correlated agreement for low-degree parameterised curves) in Proximity Gaps
161+
-/
162+
theorem correlatedAgreement_affine_curves [Fintype ι] [Nonempty ι] [Field F] [Fintype F]
163+
[DecidableEq F]
164+
{l : ℕ} (u : Fin l → ι → F) (δ : ℝ≥0) (deg : ℕ) (domain : ι ↪ F)
165+
(hδ : δ ≤ 1 - (ReedSolomonCode.sqrtRate deg domain))
166+
(hproximity : (PMF.uniformOfFintype (parametrisedCurve' u)).toOuterMeasure
167+
{y | Code.relHammingDistToCode y.1 (ReedSolomon.code domain deg) ≤ δ}
168+
> l*(proximityParams δ deg domain)):
169+
correlatedAgreement (ReedSolomon.code domain deg) δ u := by sorry
170+
171+
#check Set.range
172+
#check affineSpan
173+
/--
174+
Theorem 1.6 (Correlated agreement over affine spaces) in Proximity Gaps
175+
--- how do I represent `u` as a set?
176+
-/
177+
theorem correlatedAgreement_affine_spaces [Fintype ι] [Nonempty ι] [Field F] [Fintype F]
178+
{l : ℕ} (u : Fin (l+1) → ι → F) (δ : ℝ≥0) (deg : ℕ) (domain : ι ↪ F)
179+
(hδ : δ ≤ 1 - (ReedSolomonCode.sqrtRate deg domain))
180+
(hproximity : (PMF.uniformOfFintype (affineSpan F (Set.range u))).toOuterMeasure
181+
{y | Code.relHammingDistToCode y (ReedSolomon.code domain deg) ≤ δ}
182+
> proximityParams δ deg domain) :
183+
correlatedAgreement (ReedSolomon.code domain deg) δ u := by sorry
184+
185+
instance {l : ℕ} [NeZero l] : Nonempty (Fin l) := inferInstance
186+
187+
instance {l : ℕ} [NeZero l] : Fintype (Fin l) := inferInstance
188+
189+
-- instance {l : ℕ} [NeZero l] :
190+
-- Inhabited (Finset.univ : Finset (Fin l)) := inferInstance
191+
192+
#check Fintype.ofFinite
193+
194+
instance {α : Type} [Fintype α] [Nonempty α] :
195+
Nonempty (Finset.univ : Finset α) := by exact Nonempty.to_subtype (univ_nonempty_iff.mpr (by assumption))
196+
-- refine Nonempty.to_subtype ?_
197+
198+
199+
-- rw [← Finset.univ_nonempty_iff]
200+
-- apply Finset.univ_nonempty
201+
202+
203+
-- haveI := @Finset.univ_nonempty (Fin (l+1)) _ _
204+
-- exact this
205+
206+
207+
208+
-- apply Nonempty.intro
209+
-- exact ⟨0 , by simp⟩
210+
211+
212+
213+
theorem correlatedAgreement_affine_spaces' [Fintype ι] [Field F] [Fintype F]
214+
[DecidableEq F]
215+
{l : ℕ} [NeZero l] (u : Fin l → ι → F) (δ : ℝ≥0) (deg : ℕ) (domain : ι ↪ F)
216+
-- (hδ : δ ≤ 1 - (ReedSolomonCode.sqrtRate deg domain))
217+
(hproximity : (@PMF.uniformOfFintype (@affineSpan F F
218+
(ι → F) _ _ _ {vsub := sorry, vsub_vadd' := sorry, vadd_vsub' := sorry}
219+
(Finset.univ.image u))
220+
(let x : AffineSubspace F (ι → F) := affineSpan F ↑(image u univ)
221+
let y : Set _ := SetLike.coe x
222+
by
223+
{elems := by have : y = ↑x := by aesop
224+
simp [x] at this
225+
have : Finite y := by
226+
rw [this]
227+
exact Subtype.finite
228+
simp [y, x] at this
229+
have := Fintype.ofFinite ↑(spanPoints F (Set.range u))
230+
simp
231+
simp_rw [←coe_affineSpan] at this
232+
rcases this with ⟨s, hs⟩
233+
convert s
234+
ext x
235+
refine ⟨λ h ↦ ?p₁, λ h ↦ ?p₂⟩
236+
sorry
237+
238+
239+
done, complete := sorry}) sorry).toOuterMeasure
240+
sorry
241+
> 42.) : False := by
242+
sorry
243+
-- correlatedAgreement (ReedSolomon.code domain deg) δ u := by sorry
244+
245+
246+
--- { y : affineSpan F (Finset.univ.image u) |
247+
-- Code.relHammingDistToCode y.1 (ReedSolomon.code domain deg) ≤ δ}
248+
249+
end
250+
251+
-- import Scratch.Basic
252+
253+
-- example {α : Type} {s : Finset α} : Fintype {x | x ∈ s} :=
254+
-- Set.fintypeMemFinset s
255+
256+
257+
258+
-- -- set_option trace.auto.smt.printCommands true
259+
260+
-- -- set_option auto.smt true
261+
262+
-- -- -- example {n : ℤ} : n + 1 - 1 = n := by
263+
-- -- -- -- smt_show
264+
-- -- -- autoGetHints
265+
266+
-- -- example {x₁ x₂ α₁ : ℤ} (h₁ : 0 ≤ α₁) (h₂ : 0 ≤ 1 - α₁) (h₃ : α₁ + (1 - α₁) = 1) :
267+
-- -- 0 ≤ α₁ * (1 - α₁) * (x₁ - x₂) ^ 2 := by
268+
-- -- autoGetHints
269+
270+
271+
272+
-- def main : IO Unit := pure ()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# scratch

Scratch.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- This module serves as the root of the `Scratch` library.
2+
-- Import modules here that should be built as part of the library.
3+
import Scratch.Basic

Scratch/Basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace X
2+
3+
private def F : Nat := 42
4+
5+
end X

0 commit comments

Comments
 (0)