id int64 1 500 | thm_name stringlengths 5 86 | thm_stmt stringlengths 30 2.63k | lean_root stringclasses 23 values | rel_path stringlengths 13 61 | imports listlengths 0 35 | used_lib_defs listlengths 1 144 | used_repo_defs listlengths 1 251 | lib_lemmas listlengths 1 172 | repo_lemmas listlengths 1 148 | used_local_defs listlengths 0 85 | used_local_lemmas listlengths 0 57 | local_ctx stringlengths 35 30.7k | target_theorem stringlengths 33 1.57k | ground_truth_proof stringlengths 6 26.5k | nesting_depth int64 1 27 | transitive_dep_count int64 1 480 | subset_aristotle bool 2 classes | category stringclasses 5 values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Binius.BinaryBasefold.fiberwise_dist_lt_imp_dist_lt_unique_decoding_radius | theorem fiberwise_dist_lt_imp_dist_lt_unique_decoding_radius (i : Fin ℓ) (steps : ℕ)
[NeZero steps] (h_i_add_steps : i.val + steps ≤ ℓ)
(f : OracleFunction 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i, by omega⟩)
(h_fw_dist_lt : fiberwiseClose 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate)
(i := i) (steps := steps) (h_i_add_steps := h_i_add_steps) (f := f)) :
hammingClose 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i, by omega⟩ f | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Prelude.lean | [
"import ArkLib.Data.MvPolynomial.Multilinear",
"import ArkLib.Data.CodingTheory.Basic",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.CodingTheory.ReedSolomon",
"import ArkLib.Data.Vector.Basic",
"import ArkLib.ProofSystem.Sumcheck.Spec.S... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "hammingDist",
"content": "notation \"Δ₀(\" u \", \" v \")\" => hammingDist u v"
},
{
"name": "distFromCode",
"content": "notation \"Δ₀(\" u \", \" C \")\" => distFromCode u C"
},
{
"name": "scoped macro_rules",
"content": "scoped macro_rules\n | `(ρ $t:term) => `(LinearCo... | [
{
"name": "Fin.is_le",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Nat.lt_of_add_right_lt",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.lt_of_le_of_lt",
"module": "Init.Prelude"
},
{
"name": "Fin.eta",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "add_ze... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "lt_add_of_pos_right_of_le",
"content": "@[simp]\nlemma lt_add_of_pos_right_of_le (a b c : ℕ) [NeZero c] (h : a ≤ b) : a < b + c"
},
{
... | [
{
"name": "Binius.BinaryBasefold.OracleFunction",
"content": "abbrev OracleFunction (i : Fin (ℓ + 1)) : Type _ := sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/\n ⟩ → L"
},
{
"name": "Binius.BinaryBasefold.fiber_coeff",
"content": "noncomputable def fiber_coeff\n (i : Fin r) ... | [
{
"name": "Binius.BinaryBasefold.fin_ℓ_steps_lt_ℓ_add_R",
"content": "omit [NeZero ℓ] in\nlemma fin_ℓ_steps_lt_ℓ_add_R (i : Fin ℓ) (steps : ℕ) (h : i.val + steps ≤ ℓ)\n : i.val + steps < ℓ + 𝓡"
},
{
"name": "Binius.BinaryBasefold.qMap_total_fiber_repr_coeff",
"content": "lemma qMap_total_fib... | import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch
import ArkLib.Data.CodingTheory.ReedSolomon
import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.MvPolynomial.Multilinear
import ArkLib.Data.Vector.Basic
import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
section Preliminaries
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
end Preliminaries
noncomputable section -- expands with 𝔽q in front
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L] [CharP L 2]
variable (𝔽q : Type) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ 𝓡 ϑ : ℕ} (γ_repetitions : ℕ) [NeZero ℓ] [NeZero 𝓡] [NeZero ϑ] -- Should we allow ℓ = 0?
variable {h_ℓ_add_R_rate : ℓ + 𝓡 < r} -- ℓ ∈ {1, ..., r-1}
variable {𝓑 : Fin 2 ↪ L}
section Essentials
abbrev OracleFunction (i : Fin (ℓ + 1)) : Type _ := sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ → L
noncomputable def fiber_coeff
(i : Fin r) (steps : ℕ)
(j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))
(y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=
if hj : j.val < steps then
if Nat.getBit (k := j) (n := elementIdx) = 0 then 0 else 1
else y_coeffs ⟨j.val - steps, by admit /- proof elided -/
⟩
noncomputable def qMap_total_fiber
(i : Fin r) (steps : ℕ) (h_i_add_steps : i.val + steps < ℓ + 𝓡)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by admit /- proof elided -/
⟩)) :
Fin (2 ^ steps) → sDomain 𝔽q β h_ℓ_add_R_rate i :=
if h_steps : steps = 0 then by
subst h_steps
simp only [add_zero, Fin.eta] at y
exact fun _ => y
else by
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate (i := ⟨i+steps,by admit /- proof elided -/
⟩) (by admit /- proof elided -/
)
let y_coeffs : Fin (ℓ + 𝓡 - (↑i + steps)) →₀ 𝔽q := basis_y.repr y
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ (by admit /- proof elided -/
)
exact fun elementIdx => by admit /- proof elided -/
def pointToIterateQuotientIndex (i : Fin (ℓ + 1)) (steps : ℕ) (h_i_add_steps : i.val + steps ≤ ℓ)
(x : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩)) : Fin (2 ^ steps) :=
end Essentials
section SoundnessTools
def BBF_Code (i : Fin (ℓ + 1)) : Submodule L ((sDomain 𝔽q β h_ℓ_add_R_rate)
⟨i, by admit /- proof elided -/
⟩ → L) :=
let domain : (sDomain 𝔽q β h_ℓ_add_R_rate) ⟨i, by admit /- proof elided -/
⟩ ↪ L :=
⟨fun x => x.val, fun x y h => by admit /- proof elided -/
⟩
ReedSolomon.code (domain := domain) (deg := 2^(ℓ - i.val))
def BBF_CodeDistance (ℓ 𝓡 : ℕ) (i : Fin (ℓ + 1)) : ℕ :=
2^(ℓ + 𝓡 - i.val) - 2^(ℓ - i.val) + 1
def fiberwiseDisagreementSet (i : Fin ℓ) (steps : ℕ) [NeZero steps]
(h_i_add_steps : i.val + steps ≤ ℓ) (f g : OracleFunction 𝔽q β (h_ℓ_add_R_rate :=
h_ℓ_add_R_rate) ⟨i, by admit /- proof elided -/
⟩) :
Set ((sDomain 𝔽q β h_ℓ_add_R_rate) ⟨i.val + steps, by admit /- proof elided -/
⟩) :=
{y | ∃ x, iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate (i := i)
(k := steps) (h_bound := by admit /- proof elided -/
) x = y ∧ f x ≠ g x}
def fiberwiseDistance (i : Fin ℓ) (steps : ℕ) [NeZero steps] (h_i_add_steps : i.val + steps ≤ ℓ)
(f : OracleFunction 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i.val, by admit /- proof elided -/
⟩) : ℕ :=
let C_i := BBF_Code 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i.val, by admit /- proof elided -/
⟩
let disagreement_sizes := (fun (g : C_i) =>
(fiberwiseDisagreementSet 𝔽q β i steps h_i_add_steps f g).ncard) '' Set.univ
sInf disagreement_sizes
def fiberwiseClose (i : Fin ℓ) (steps : ℕ) [NeZero steps] (h_i_add_steps : i.val + steps ≤ ℓ)
(f : OracleFunction 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate)
⟨i, by admit /- proof elided -/
⟩) : Prop :=
2 * fiberwiseDistance 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) (i := i) steps
(h_i_add_steps := h_i_add_steps) (f := f) < (BBF_CodeDistance ℓ 𝓡 ⟨i + steps, by admit /- proof elided -/
⟩ : ℕ∞)
def hammingClose (i : Fin (ℓ + 1)) (f : OracleFunction 𝔽q β
(h_ℓ_add_R_rate := h_ℓ_add_R_rate) i) : Prop :=
2 * Code.distFromCode (u := f)
(C := BBF_Code 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) i) <
(BBF_CodeDistance ℓ 𝓡 i : ℕ∞) | theorem fiberwise_dist_lt_imp_dist_lt_unique_decoding_radius (i : Fin ℓ) (steps : ℕ)
[NeZero steps] (h_i_add_steps : i.val + steps ≤ ℓ)
(f : OracleFunction 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i, by omega⟩)
(h_fw_dist_lt : fiberwiseClose 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate)
(i := i) (steps := steps) (h_i_add_steps := h_i_add_steps) (f := f)) :
hammingClose 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i, by omega⟩ f := | := by
unfold fiberwiseClose at h_fw_dist_lt
unfold hammingClose
-- 2 * Δ₀(f, ↑(BBF_Code 𝔽q β ⟨↑i, ⋯⟩)) < ↑(BBF_CodeDistance ℓ 𝓡 ⟨↑i, ⋯⟩)
let d_fw := fiberwiseDistance 𝔽q β (i := i) steps h_i_add_steps f
let C_i := (BBF_Code 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i, by omega⟩)
let d_H := Code.distFromCode f C_i
let d_i := BBF_CodeDistance ℓ 𝓡 (⟨i, by omega⟩)
let d_i_plus_steps := BBF_CodeDistance ℓ 𝓡 ⟨i.val + steps, by omega⟩
have h_d_i_gt_0 : d_i > 0 := by
dsimp [d_i, BBF_CodeDistance] -- ⊢ 2 ^ (ℓ + 𝓡 - ↑i) - 2 ^ (ℓ - ↑i) + 1 > 0
have h_exp_lt : ℓ - i.val < ℓ + 𝓡 - i.val := by
exact Nat.sub_lt_sub_right (a := ℓ) (b := ℓ + 𝓡) (c := i.val) (by omega) (by
apply Nat.lt_add_of_pos_right; exact pos_of_neZero 𝓡)
have h_pow_lt : 2 ^ (ℓ - i.val) < 2 ^ (ℓ + 𝓡 - i.val) := by
exact Nat.pow_lt_pow_right (by norm_num) h_exp_lt
omega
have h_C_i_nonempty : Nonempty C_i := by
simp only [nonempty_subtype, C_i]
exact Submodule.nonempty (BBF_Code 𝔽q β (h_ℓ_add_R_rate := h_ℓ_add_R_rate) ⟨i.val, by omega⟩)
-- 1. Relate Hamming distance `d_H` to fiber-wise distance `d_fw`.
obtain ⟨g', h_g'_mem, h_g'_min_card⟩ : ∃ g' ∈ C_i, d_fw
= (fiberwiseDisagreementSet 𝔽q β i steps h_i_add_steps f g').ncard := by
-- Let `S` be the set of all possible fiber-wise disagreement sizes.
let S := (fun (g : C_i) => (fiberwiseDisagreementSet 𝔽q β i steps h_i_add_steps
f g).ncard) '' Set.univ
-- The code `C_i` (a submodule) is non-empty, so `S` is also non-empty.
have hS_nonempty : S.Nonempty := by
refine Set.image_nonempty.mpr ?_
exact Set.univ_nonempty
-- For a non-empty set of natural numbers, `sInf` is an element of the set.
have h_sInf_mem : sInf S ∈ S := Nat.sInf_mem hS_nonempty
-- By definition, `d_fw = sInf S`.
unfold d_fw at h_sInf_mem
-- Since `sInf S` is in the image set `S`, there must be an element `g_subtype` in the domain
-- (`C_i`) that maps to it. This `g_subtype` is the codeword we're looking for.
rw [Set.mem_image] at h_sInf_mem
rcases h_sInf_mem with ⟨g_subtype, _, h_eq⟩
-- Extract the codeword and its membership proof.
exact ⟨g_subtype.val, g_subtype.property, by exact id (Eq.symm h_eq)⟩
-- The Hamming distance to any codeword `g'` is bounded by `d_fw * 2 ^ steps`.
have h_dist_le_fw_dist_times_fiber_size : (hammingDist f g' : ℕ∞) ≤ d_fw * 2 ^ steps := by
-- This proves `dist f g' ≤ (fiberwiseDisagreementSet ... f g').ncard * 2 ^ steps`
-- and lifts to ℕ∞. We prove the `Nat` version `hammingDist f g' ≤ ...`,
-- which is equivalent.
change (Δ₀(f, g') : ℕ∞) ≤ ↑d_fw * ((2 ^ steps : ℕ) : ℕ∞)
rw [←ENat.coe_mul, ENat.coe_le_coe, h_g'_min_card]
-- Let ΔH be the finset of actually bad x points where f and g' disagree.
set ΔH := Finset.filter (fun x => f x ≠ g' x) Finset.univ
have h_dist_eq_card : hammingDist f g' = ΔH.card := by
simp only [hammingDist, ne_eq, ΔH]
rw [h_dist_eq_card]
-- Y_bad is the set of quotient points y that THERE EXISTS a bad fiber point x
set Y_bad := fiberwiseDisagreementSet 𝔽q β i steps h_i_add_steps f g'
simp only at * -- simplify domain indices everywhere
-- ⊢ #ΔH ≤ Y_bad.ncard * 2 ^ steps
have hFinType_Y_bad : Fintype Y_bad := by exact Fintype.ofFinite ↑Y_bad
-- Every point of disagreement `x` must belong to a fiber over some `y` in `Y_bad`,
-- BY DEFINITION of `Y_bad`. Therefore, `ΔH` is a subset of the union of the fibers
-- of `Y_bad`
have h_ΔH_subset_bad_fiber_points : ΔH ⊆ Finset.biUnion Y_bad.toFinset
(t := fun y => ((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y)) ''
(Finset.univ : Finset (Fin ((2:ℕ)^steps)))).toFinset) := by
-- ⊢ If any x ∈ ΔH, then x ∈ Union(qMap_total_fiber(y), ∀ y ∈ Y_bad)
intro x hx_in_ΔH; -- ⊢ x ∈ Union(qMap_total_fiber(y), ∀ y ∈ Y_bad)
simp only [ΔH, Finset.mem_filter] at hx_in_ΔH
-- Now we actually apply iterated qMap into x to get y_of_x,
-- then x ∈ qMap_total_fiber(y_of_x) by definition
let y_of_x := iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i steps h_i_add_steps x
apply Finset.mem_biUnion.mpr; use y_of_x
-- ⊢ y_of_x ∈ Y_bad.toFinset ∧ x ∈ qMap_total_fiber(y_of_x)
have h_elemenet_Y_bad : y_of_x ∈ Y_bad.toFinset := by
-- ⊢ y ∈ Y_bad.toFinset
simp only [fiberwiseDisagreementSet, iteratedQuotientMap, ne_eq, Subtype.exists,
Set.toFinset_setOf, mem_filter, mem_univ, true_and, Y_bad]
-- one bad fiber point of y_of_x is x itself
let X := x.val
have h_X_in_source : X ∈ sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) := by
exact Submodule.coe_mem x
use X
use h_X_in_source
-- ⊢ Ŵ_steps⁽ⁱ⁾(X) = y (iterated quotient map) ∧ ¬f ⟨X, ⋯⟩ = g' ⟨X, ⋯⟩
have h_forward_iterated_qmap : Polynomial.eval X
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩
⟨steps, by simp only; omega⟩) = y_of_x := by
simp only [iteratedQuotientMap, X, y_of_x];
have h_eval_diff : f ⟨X, by omega⟩ ≠ g' ⟨X, by omega⟩ := by
unfold X
simp only [Subtype.coe_eta, ne_eq, hx_in_ΔH, not_false_eq_true]
simp only [h_forward_iterated_qmap, Subtype.coe_eta, h_eval_diff,
not_false_eq_true, and_self]
simp only [h_elemenet_Y_bad, true_and]
set qMapFiber := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y_of_x)
simp only [coe_univ, Set.image_univ, Set.toFinset_range, mem_image, mem_univ, true_and]
use (pointToIterateQuotientIndex (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by omega) (x := x))
have h_res := is_fiber_iff_generates_quotient_point 𝔽q β i steps (by omega)
(x := x) (y := y_of_x).mp (by rfl)
exact h_res
-- ⊢ #ΔH ≤ Y_bad.ncard * 2 ^ steps
-- The cardinality of a subset is at most the cardinality of the superset.
apply (Finset.card_le_card h_ΔH_subset_bad_fiber_points).trans
-- The cardinality of a disjoint union is the sum of cardinalities.
rw [Finset.card_biUnion]
· -- The size of the sum is the number of bad fibers (`Y_bad.ncard`) times
-- the size of each fiber (`2 ^ steps`).
simp only [Set.toFinset_card]
have h_card_fiber_per_quotient_point := card_qMap_total_fiber 𝔽q β
(h_ℓ_add_R_rate := h_ℓ_add_R_rate) i steps h_i_add_steps
simp only [Set.image_univ, Fintype.card_ofFinset,
Subtype.forall] at h_card_fiber_per_quotient_point
have h_card_fiber_of_each_y : ∀ y ∈ Y_bad.toFinset,
Fintype.card ((qMap_total_fiber 𝔽q β (i := ⟨↑i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y)) ''
↑(Finset.univ : Finset (Fin ((2:ℕ)^steps)))) = 2 ^ steps := by
intro y hy_in_Y_bad
have hy_card_fiber_of_y := h_card_fiber_per_quotient_point (a := y) (b := by
exact Submodule.coe_mem y)
simp only [coe_univ, Set.image_univ, Fintype.card_ofFinset, hy_card_fiber_of_y]
rw [Finset.sum_congr rfl h_card_fiber_of_each_y]
-- ⊢ ∑ x ∈ Y_bad.toFinset, 2 ^ steps ≤ Y_bad.encard.toNat * 2 ^ steps
simp only [sum_const, Set.toFinset_card, smul_eq_mul, ofNat_pos, pow_pos,
_root_.mul_le_mul_right, ge_iff_le]
conv_rhs => rw [←_root_.Nat.card_coe_set_eq] -- convert .ncard back to .card
-- ⊢ Fintype.card ↑Y_bad ≤ Nat.card ↑Y_bad
simp only [card_eq_fintype_card, le_refl]
· -- Prove that the fibers for distinct quotient points y₁, y₂ are disjoint.
intro y₁ hy₁ y₂ hy₂ hy_ne
have h_disjoint := qMap_total_fiber_disjoint (i := ⟨↑i, by omega⟩) (steps := steps)
(h_i_add_steps := by omega) (y₁ := y₁) (y₂ := y₂) (hy_ne := hy_ne)
simp only [Function.onFun, coe_univ]
exact h_disjoint
-- The minimum distance `d_H` is bounded by the distance to this specific `g'`.
have h_dist_bridge : d_H ≤ d_fw * 2 ^ steps := by
-- exact h_dist_le_fw_dist_times_fiber_size
apply le_trans (a := d_H) (c := d_fw * 2 ^ steps) (b := hammingDist f g')
· -- ⊢ d_H ≤ ↑Δ₀(f, g')
simp only [distFromCode, SetLike.mem_coe, hammingDist, ne_eq, d_H];
-- ⊢ Δ₀(f, C_i) ≤ ↑Δ₀(f, g')
-- ⊢ sInf {d | ∃ v ∈ C_i, ↑(#{i | f i ≠ v i}) ≤ d} ≤ ↑(#{i | f i ≠ g' i})
apply sInf_le
use g'
· exact h_dist_le_fw_dist_times_fiber_size
-- 2. Use the premise : `2 * d_fw < d_{i+steps}`.
-- As a `Nat` inequality, this is equivalent to `2 * d_fw ≤ d_{i+steps} - 1`.
have h_fw_bound : 2 * d_fw ≤ d_i_plus_steps - 1 := by
-- Convert the ENat inequality to a Nat inequality using `a < b ↔ a + 1 ≤ b`.
exact Nat.le_of_lt_succ (WithTop.coe_lt_coe.1 h_fw_dist_lt)
-- 3. The Algebraic Identity.
-- The core of the proof is the identity : `(d_{i+steps} - 1) * 2 ^ steps = d_i - 1`.
have h_algebraic_identity : (d_i_plus_steps - 1) * 2 ^ steps = d_i - 1 := by
dsimp [d_i, d_i_plus_steps, BBF_CodeDistance]
rw [Nat.sub_mul, ←Nat.pow_add, ←Nat.pow_add];
have h1 : ℓ + 𝓡 - (↑i + steps) + steps = ℓ + 𝓡 - i := by
rw [Nat.sub_add_eq_sub_sub_rev (h1 := by omega) (h2 := by omega),
Nat.add_sub_cancel (n := i) (m := steps)]
have h2 : (ℓ - (↑i + steps) + steps) = ℓ - i := by
rw [Nat.sub_add_eq_sub_sub_rev (h1 := by omega) (h2 := by omega),
Nat.add_sub_cancel (n := i) (m := steps)]
rw [h1, h2]
-- 4. Conclusion : Chain the inequalities to prove `2 * d_H < d_i`.
-- We know `d_H` is finite, since `C_i` is nonempty.
have h_dH_ne_top : d_H ≠ ⊤ := by
simp only [ne_eq, d_H]
rw [Code.distFromCode_eq_top_iff_empty f C_i]
exact Set.nonempty_iff_ne_empty'.mp h_C_i_nonempty
-- We can now work with the `Nat` value of `d_H`.
let d_H_nat := ENat.toNat d_H
have h_dH_eq : d_H = d_H_nat := (ENat.coe_toNat h_dH_ne_top).symm
-- The calculation is now done entirely in `Nat`.
have h_final_inequality : 2 * d_H_nat ≤ d_i - 1 := by
have h_bridge_nat : d_H_nat ≤ d_fw * 2 ^ steps := by
rw [←ENat.coe_le_coe]
exact le_of_eq_of_le (id (Eq.symm h_dH_eq)) h_dist_bridge
calc 2 * d_H_nat
_ ≤ 2 * (d_fw * 2 ^ steps) := by gcongr
_ = (2 * d_fw) * 2 ^ steps := by rw [mul_assoc]
_ ≤ (d_i_plus_steps - 1) * 2 ^ steps := by gcongr;
_ = d_i - 1 := h_algebraic_identity
simp only [d_H, d_H_nat] at h_dH_eq
-- This final line is equivalent to the goal statement.
rw [h_dH_eq]
-- ⊢ 2 * ↑Δ₀(f, C_i).toNat < ↑(BBF_CodeDistance ℓ 𝓡 ⟨↑i, ⋯⟩)
change ((2 : ℕ) : ℕ∞) * ↑Δ₀(f, C_i).toNat < ↑(BBF_CodeDistance ℓ 𝓡 ⟨↑i, by omega⟩)
rw [←ENat.coe_mul, ENat.coe_lt_coe]
apply Nat.lt_of_le_pred (n := 2 * Δ₀(f, C_i).toNat) (m := d_i) (h := h_d_i_gt_0)
(h_final_inequality) | 7 | 232 | false | Applied verif. |
2 | ConcreteBinaryTower.minPoly_of_powerBasisSucc_generator | @[simp]
theorem minPoly_of_powerBasisSucc_generator (k : ℕ) :
(minpoly (ConcreteBTField k) (powerBasisSucc k).gen) = X^2 + (Z k) • X + 1 | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le
def join_via_add_smul (k : ℕ) (h_pos : k > 0) (hi_btf lo_btf : ConcreteBTField (k - 1)) :
ConcreteBTField k :=
end ConcreteBTFieldAlgebraConstruction
noncomputable section ConcreteMultilinearBasis
open Module
def basisSucc (k : ℕ) : Basis (Fin 2) (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
def powerBasisSucc (k : ℕ) :
PowerBasis (ConcreteBTField k) (ConcreteBTField (k + 1)) := | @[simp]
theorem minPoly_of_powerBasisSucc_generator (k : ℕ) :
(minpoly (ConcreteBTField k) (powerBasisSucc k).gen) = X^2 + (Z k) • X + 1 := | := by
unfold powerBasisSucc
simp only
rw [←C_mul']
letI: Fintype (ConcreteBTField k) := (getBTFResult k).instFintype
refine Eq.symm (minpoly.unique' (ConcreteBTField k) (Z (k + 1)) ?_ ?_ ?_)
· exact (definingPoly_is_monic (s:=Z (k)))
· exact aeval_definingPoly_at_Z_succ k
· intro q h_degQ_lt_deg_minPoly
-- h_degQ_lt_deg_minPoly : q.degree < (X ^ 2 + Z k • X + 1).degree
-- ⊢ q = 0 ∨ (aeval (Z (k + 1))) q ≠ 0
have h_degree_definingPoly : (definingPoly (s:=Z (k))).degree = 2 := by
exact degree_definingPoly (s:=Z (k))
rw [←definingPoly, h_degree_definingPoly] at h_degQ_lt_deg_minPoly
if h_q_is_zero : q = 0 then
rw [h_q_is_zero]
simp only [map_zero, ne_eq, not_true_eq_false, or_false]
else
-- reason stuff related to IsUnit here
have h_q_is_not_zero : q ≠ 0 := by omega
simp only [h_q_is_zero, ne_eq, false_or]
-- ⊢ ¬(aeval (Z (k + 1))) q = 0
have h_deg_q_ne_bot : q.degree ≠ ⊥ := by
exact degree_ne_bot.mpr h_q_is_zero
have q_natDegree_lt_2 : q.natDegree < 2 := by
exact (natDegree_lt_iff_degree_lt h_q_is_zero).mpr h_degQ_lt_deg_minPoly
-- do case analysis on q.degree
interval_cases hqNatDeg : q.natDegree
· simp only [ne_eq]
have h_q_is_c : ∃ r : ConcreteBTField k, q = C r := by
use q.coeff 0
exact Polynomial.eq_C_of_natDegree_eq_zero hqNatDeg
let hx := h_q_is_c.choose_spec
set x := h_q_is_c.choose
simp only [hx, aeval_C, map_eq_zero, ne_eq]
-- ⊢ ¬x = 0
by_contra h_x_eq_0
simp only [h_x_eq_0, map_zero] at hx -- hx : q = 0, h_q_is_not_zero : q ≠ 0
contradiction
· have h_q_natDeg_ne_0 : q.natDegree ≠ 0 := by exact ne_zero_of_eq_one hqNatDeg
have h_q_deg_ne_0 : q.degree ≠ 0 := by
by_contra h_q_deg_is_0
have h_q_natDeg_is_0 : q.natDegree = 0 := by exact
(degree_eq_iff_natDegree_eq h_q_is_zero).mp h_q_deg_is_0
contradiction
have h_natDeg_q_is_1 : q.natDegree = 1 := by exact hqNatDeg
have h_deg_q_is_1 : q.degree = 1 := by
apply (degree_eq_iff_natDegree_eq h_q_is_zero).mpr
exact hqNatDeg
have h_q_is_not_unit : ¬IsUnit q := by
by_contra h_q_is_unit
rw [←is_unit_iff_deg_0] at h_q_is_unit
contradiction
let c := q.coeff 1
let r := q.coeff 0
have hc : c = q.leadingCoeff := by
rw [Polynomial.leadingCoeff]
exact congrArg q.toFinsupp.2 (id (Eq.symm hqNatDeg))
have hc_ne_zero : c ≠ 0 := by
rw [hc]
by_contra h_c_eq_zero
simp only [leadingCoeff_eq_zero] at h_c_eq_zero -- h_c_eq_zero : q = 0
contradiction
have hq_form : q = c • X + C r := by
rw [Polynomial.eq_X_add_C_of_degree_eq_one (p:=q) (h:=by exact h_deg_q_is_1)]
congr
rw [hc]
exact C_mul' q.leadingCoeff X
-- ⊢ ¬(aeval (Z (k + 1))) q = 0
simp only [hq_form, map_add, map_smul, aeval_X, aeval_C, ne_eq]
-- ⊢ ¬Z k • Z (k + 1) + (algebraMap (ConcreteBTField k) (ConcreteBTField (k + 1))) x = 0
have h_split_smul := split_smul_Z_eq_zero_x (k:=k+1) (h_pos:=by omega) (x:=c)
rw [smul_Z_eq_zero_x (k:=k+1) (h_pos:=by omega) (x:=c)]
have h_alg_map_x := algebraMap_succ_eq_zero_x (k:=k+1) (h_pos:=by omega) (x:=r)
simp only [Nat.add_one_sub_one] at h_alg_map_x
rw [h_alg_map_x, join_add_join]
simp only [Nat.add_one_sub_one, _root_.add_zero, _root_.zero_add,
ne_eq]
-- ⊢ ¬join ⋯ c x = 0
by_contra h_join_eq_zero
conv_rhs at h_join_eq_zero =>
rw [←zero_is_0];
rw! [←join_zero_zero (k:=k+1) (h_k:=by omega)]
rw [join_eq_join_iff] at h_join_eq_zero
have h_c_eq_zero := h_join_eq_zero.1
contradiction | 16 | 324 | false | Applied verif. |
3 | AdditiveNTT.evaluation_poly_split_identity | theorem evaluation_poly_split_identity (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) :
let P_i: L[X] := intermediateEvaluationPoly 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ coeffs
let P_even_i_plus_1: L[X] := evenRefinement 𝔽q β h_ℓ_add_R_rate i coeffs
let P_odd_i_plus_1: L[X] := oddRefinement 𝔽q β h_ℓ_add_R_rate i coeffs
let q_i: L[X] := qMap 𝔽q β ⟨i, by omega⟩
P_i = (P_even_i_plus_1.comp q_i) + X * (P_odd_i_plus_1.comp q_i) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Polynomial.comp_assoc",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fin.foldl_succ",
"module": "Init.Data.Fin.Fol... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "getBit_eq_succ_getBit_of_mul_two_add_one",
"content": "lemma getBit_eq_succ_getBit_of_mul_two_add_one {n k : ℕ} : getBit (k+1) (2*n + 1) = get... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.intermedia... | [
{
"name": "AdditiveNTT.Polynomial.foldl_comp",
"content": "omit [Fintype L] [DecidableEq L] in\ntheorem Polynomial.foldl_comp (n : ℕ) (f : Fin n → L[X]) : ∀ initInner initOuter: L[X],\n Fin.foldl (n:=n) (fun acc j => (f j).comp acc) (initOuter.comp initInner)\n = (Fin.foldl (n:=n) (fun acc j => (f j).... | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X)
noncomputable def intermediateNovelBasisX (i : Fin (ℓ + 1)) (j : Fin (2 ^ (ℓ - i))) : L[X] :=
(Finset.univ: Finset (Fin (ℓ - i)) ).prod (fun k =>
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate i (k:=⟨k, by admit /- proof elided -/
⟩)) ^ (Nat.getBit k j))
noncomputable def intermediateEvaluationPoly (i : Fin (ℓ + 1))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i))), C (coeffs ⟨j, by admit /- proof elided -/
⟩) *
(intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate i ⟨j, by admit /- proof elided -/
⟩)
noncomputable def evenRefinement (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i-1))), C (coeffs ⟨j*2, by admit /- proof elided -/
⟩) * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by admit /- proof elided -/
⟩ ⟨j, hj⟩)
noncomputable def oddRefinement (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i-1))), C (coeffs ⟨j*2+1, by admit /- proof elided -/
⟩) * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by admit /- proof elided -/
⟩ ⟨j, hj⟩) | theorem evaluation_poly_split_identity (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) :
let P_i: L[X] := | := intermediateEvaluationPoly 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ coeffs
let P_even_i_plus_1: L[X] := evenRefinement 𝔽q β h_ℓ_add_R_rate i coeffs
let P_odd_i_plus_1: L[X] := oddRefinement 𝔽q β h_ℓ_add_R_rate i coeffs
let q_i: L[X] := qMap 𝔽q β ⟨i, by omega⟩
P_i = (P_even_i_plus_1.comp q_i) + X * (P_odd_i_plus_1.comp q_i) := by
simp only [intermediateEvaluationPoly, Fin.eta]
simp only [evenRefinement, Fin.eta, sum_comp, mul_comp, C_comp, oddRefinement]
set leftEvenTerm := ∑ ⟨j, hj⟩ : Fin (2 ^ (ℓ - ↑i - 1)), C (coeffs ⟨j * 2, by
exact mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
⟩) * intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨j * 2, by
exact mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
⟩
set leftOddTerm := ∑ ⟨j, hj⟩ : Fin (2 ^ (ℓ - ↑i - 1)), C (coeffs ⟨j * 2 + 1, by
apply mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
⟩) * intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨j * 2 + 1, by
exact mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
⟩
have h_split_P_i: ∑ ⟨j, hj⟩ : Fin (2 ^ (ℓ - ↑i)), C (coeffs ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le j (ℓ-i) (ℓ-i) (by omega) (by omega)
⟩) * intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨j, by omega⟩ =
leftEvenTerm + leftOddTerm
:= by
unfold leftEvenTerm leftOddTerm
simp only [Fin.eta]
-- ⊢ ∑ k ∈ Fin (2 ^ (ℓ - ↑i)), C (coeffsₖ) * Xₖ⁽ⁱ⁾(X) = -- just pure even odd split
-- ∑ k ∈ Fin (2 ^ (ℓ - ↑i - 1)), C (coeffs₂ₖ) * X₂ₖ⁽ⁱ⁾(X) +
-- ∑ k ∈ Fin (2 ^ (ℓ - ↑i - 1)), C (coeffs₂ₖ+1) * X₂ₖ+1⁽ⁱ⁾(X)
set f1 := fun x: ℕ => -- => use a single function to represent the sum
if hx: x < 2 ^ (ℓ - ↑i) then
C (coeffs ⟨x, hx⟩) *
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨x, by omega⟩
else 0
have h_x: ∀ x: Fin (2 ^ (ℓ - ↑i)), f1 x.val =
C (coeffs ⟨x.val, by omega⟩) *
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩
⟨x.val, by simp only; omega⟩ := by
intro x
unfold f1
simp only [Fin.is_lt, ↓reduceDIte, Fin.eta]
conv_lhs =>
enter [2, x]
rw [←h_x x]
have h_x_2: ∀ x: Fin (2 ^ (ℓ - ↑i - 1)), f1 (x*2) =
C (coeffs ⟨x.val * 2, by
calc _ < 2 ^ (ℓ - i - 1) * 2 := by omega
_ = 2 ^ (ℓ - i) := Nat.two_pow_pred_mul_two (w:=ℓ - i) (h:=by omega)
⟩) *
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨x.val * 2, by
exact mul_two_add_bit_lt_two_pow x.val (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
⟩ := by
intro x
unfold f1
simp only
have h_x_lt_2_pow_i_minus_1 :=
mul_two_add_bit_lt_two_pow x.val (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
simp at h_x_lt_2_pow_i_minus_1
simp only [h_x_lt_2_pow_i_minus_1, ↓reduceDIte]
conv_rhs =>
enter [1, 2, x]
rw [←h_x_2 x]
have h_x_3: ∀ x: Fin (2 ^ (ℓ - ↑i - 1)), f1 (x*2+1) =
C (coeffs ⟨x.val * 2 + 1, by
calc _ < 2 ^ (ℓ - i - 1) * 2 := by omega
_ = 2 ^ (ℓ - i) := Nat.two_pow_pred_mul_two (w:=ℓ - i) (h:=by omega)
⟩) *
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩ ⟨x.val * 2 + 1, by
exact mul_two_add_bit_lt_two_pow x.val (ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
⟩ := by
intro x
unfold f1
simp only
have h_x_lt_2_pow_i_minus_1 := mul_two_add_bit_lt_two_pow x.val
(ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
simp only [h_x_lt_2_pow_i_minus_1, ↓reduceDIte]
conv_rhs =>
enter [2, 2, x]
rw [←h_x_3 x]
-- ⊢ ∑ x, f1 ↑x = ∑ x, f1 (↑x * 2) + ∑ x, f1 (↑x * 2 + 1)
have h_1: ∑ i ∈ Finset.range (2 ^ (ℓ - ↑i)), f1 i
= ∑ i ∈ Finset.range (2 ^ (ℓ - ↑i - 1 + 1)), f1 i := by
congr
omega
have res := Fin.sum_univ_odd_even (f:=f1) (n:=(ℓ - ↑i - 1))
conv_rhs at res =>
rw [Fin.sum_univ_eq_sum_range]
rw [←h_1]
rw [←Fin.sum_univ_eq_sum_range]
rw [←res]
congr
· funext i
rw [mul_comm]
· funext i
rw [mul_comm]
conv_lhs => rw [h_split_P_i]
set rightEvenTerm := ∑ ⟨j, hj⟩ : Fin (2 ^ (ℓ - ↑i - 1)),
C (coeffs ⟨j * 2, by
calc _ < 2 ^ (ℓ - i - 1) * 2 := by omega
_ = 2 ^ (ℓ - i) := Nat.two_pow_pred_mul_two (w:=ℓ - i) (h:=by omega)
⟩) *
(intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i + 1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le (x:=j)
(i := ℓ-↑i-1) (j:=ℓ-↑i-1) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩)
set rightOddTerm :=
X *
∑ ⟨j, hj⟩ : Fin (2 ^ (ℓ - ↑i - 1)),
C (coeffs ⟨j * 2 + 1, by
calc _ < 2 ^ (ℓ - i - 1) * 2 := by omega
_ = 2 ^ (ℓ - i) := Nat.two_pow_pred_mul_two (w:=ℓ - i) (h:=by omega)
⟩) *
(intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i + 1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le (x:=j)
(i := ℓ-↑i-1) (j:=ℓ-↑i-1) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩)
conv_rhs => change rightEvenTerm + rightOddTerm
have h_right_even_term: leftEvenTerm = rightEvenTerm := by
unfold rightEvenTerm leftEvenTerm
apply Finset.sum_congr rfl
intro j hj
simp only [Fin.eta, mul_eq_mul_left_iff, map_eq_zero]
-- X₂ⱼ⁽ⁱ⁾ = Xⱼ⁽ⁱ⁺¹⁾(q⁽ⁱ⁾(X)) ∨ a₂ⱼ = 0
by_cases h_a_j_eq_0: coeffs ⟨j * 2, by
calc _ < 2 ^ (ℓ - i - 1) * 2 := by omega
_ = 2 ^ (ℓ - i) := Nat.two_pow_pred_mul_two (w:=ℓ - i) (h:=by omega)
⟩ = 0
· simp only [h_a_j_eq_0, or_true]
· simp only [h_a_j_eq_0, or_false]
-- X₂ⱼ⁽ⁱ⁾ = Xⱼ⁽ⁱ⁺¹⁾(q⁽ⁱ⁾(X))
exact even_index_intermediate_novel_basis_decomposition
𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) j
have h_right_odd_term: rightOddTerm = leftOddTerm := by
unfold rightOddTerm leftOddTerm
simp only [Fin.eta]
conv_rhs =>
simp only [Fin.is_lt, odd_index_intermediate_novel_basis_decomposition, Fin.eta]
enter [2, x];
rw [mul_comm (a:=X)]
rw [Finset.mul_sum]
congr
funext x
ring_nf -- just associativity and commutativity of multiplication in L[X]
rw [h_right_even_term, h_right_odd_term] | 7 | 78 | false | Applied verif. |
4 | Nat.getBit_repr | theorem getBit_repr {ℓ : Nat} : ∀ j, j < 2^ℓ →
j = ∑ k ∈ Finset.Icc 0 (ℓ-1), (getBit k j) * 2^k | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.Icc",
"module": "Mathlib.Order.Interval.Finset.Defs"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "AddCommMonoid",
"module":... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.shiftRight_add",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "add_comm",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Finset.Icc_self",
"module": "Mathlib.Order.Interval.Finset.Basic"
},
{
"name": "Finset.mem_Icc",
"module": "Mathlib.Order.... | [
{
"name": "sum_Icc_split",
"content": "theorem sum_Icc_split {α : Type*} [AddCommMonoid α] (f : ℕ → α) (a b c : ℕ)\n (h₁ : a ≤ b) (h₂ : b ≤ c):\n ∑ i ∈ Finset.Icc a c, f i = ∑ i ∈ Finset.Icc a b, f i + ∑ i ∈ Finset.Icc (b+1) c, f i"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Nat.getBit_of_shiftRight",
"content": "lemma getBit_of_shiftRight {n p : ℕ}:\n ∀ k, getBit k (n >>> p) = getBit (k+p) n"
}
] | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1 | theorem getBit_repr {ℓ : Nat} : ∀ j, j < 2^ℓ →
j = ∑ k ∈ Finset.Icc 0 (ℓ-1), (getBit k j) * 2^k := | := by
induction ℓ with
| zero =>
-- Base case : ℓ = 0
intro j h_j
have h_j_zero : j = 0 := by exact Nat.lt_one_iff.mp h_j
subst h_j_zero
simp only [zero_tsub, Finset.Icc_self, Finset.sum_singleton, pow_zero, mul_one]
unfold getBit
rw [Nat.shiftRight_zero, Nat.and_one_is_mod]
| succ ℓ₁ ih =>
by_cases h_ℓ₁ : ℓ₁ = 0
· simp only [h_ℓ₁, zero_add, pow_one, tsub_self, Finset.Icc_self, Finset.sum_singleton,
pow_zero, mul_one];
intro j hj
interval_cases j
· simp only [getBit, Nat.shiftRight_zero, Nat.and_one_is_mod, Nat.zero_mod]
· simp only [getBit, Nat.shiftRight_zero, Nat.and_one_is_mod]
· push_neg at h_ℓ₁
set ℓ := ℓ₁ + 1
have h_ℓ_eq : ℓ = ℓ₁ + 1 := by rfl
intro j h_j
-- Inductive step : assume theorem holds for ℓ₁ = ℓ - 1
-- => show j = ∑ k ∈ Finset.range (ℓ + 1), (getBit k j) * 2^k
-- Split j into lowBits (b) and higher getLowBits (m) &
-- reason inductively from the predicate of (m, ℓ₁)
set b := getBit 0 j -- Least significant getBit : j % 2
set m := j >>> 1 -- Higher getLowBits : j / 2
have h_b_eq : b = getBit 0 j := by rfl
have h_m_eq : m = j >>> 1 := by rfl
have h_getBit_shift : ∀ k, getBit (k+1) j = getBit k m := by
intro k
rw [h_m_eq]
exact (getBit_of_shiftRight (n := j) (p := 1) k).symm
have h_j_eq : j = b + 2 * m := by
calc
_ = 2 * m + b := by
have h_m_eq : m = j/2 := by rfl
have h_b_eq : b = j%2 := by
rw [h_b_eq]; unfold getBit; rw [Nat.shiftRight_zero]; rw [Nat.and_one_is_mod];
rw [h_m_eq, h_b_eq];
rw [Nat.div_add_mod (m := j) (n := 2)]; -- n * (m / n) + m % n = m := by
_ = b + 2 * m := by omega;
have h_m : m < 2^ℓ₁ := by
by_contra h_m_ge_2_pow_ℓ
push_neg at h_m_ge_2_pow_ℓ
have h_j_ge : j ≥ 2^ℓ := by
calc _ = 2 * m + b := by rw [h_j_eq]; omega
_ ≥ 2 * (2^ℓ₁) + b := by omega
_ = 2^ℓ + b := by rw [h_ℓ_eq]; omega;
_ ≥ 2^ℓ := by omega;
exact Nat.not_lt_of_ge h_j_ge h_j -- contradiction
have h_m_repr := ih (j := m) h_m
have getBit_shift : ∀ k, getBit (k + 1) j = getBit k m := by
intro k
rw [h_m_eq]
exact (getBit_of_shiftRight (n := j) (p := 1) k).symm
-- ⊢ j = ∑ k ∈ Finset.range ℓ, getBit k j * 2 ^ k
have h_sum : ∑ k ∈ Finset.Icc 0 (ℓ-1), getBit k j * 2 ^ k
= (∑ k ∈ Finset.Icc 0 0, getBit k j * 2 ^ k)
+ (∑ k ∈ Finset.Icc 1 (ℓ-1), getBit k j * 2 ^ k) := by
apply sum_Icc_split
omega
omega
rw [h_sum]
rw [h_j_eq]
rw [Finset.Icc_self, Finset.sum_singleton, pow_zero, mul_one]
have h_sum_2 : ∑ k ∈ Finset.Icc 1 (ℓ-1), getBit k (b + 2 * m) * 2 ^ k
= ∑ k ∈ Finset.Icc 0 (ℓ₁-1), getBit k (m) * 2 ^ (k+1) := by
apply Finset.sum_bij' (fun i _ => i - 1) (fun i _ => i + 1)
· -- left inverse
intro i hi
simp only [Finset.mem_Icc] at hi ⊢
exact Nat.sub_add_cancel hi.1
· -- right inverse
intro i hi
norm_num
· -- function value match
intro i hi
rw [←h_j_eq]
rw [getBit_of_shiftRight]
have ⟨left_bound, right_bound⟩ := Finset.mem_Icc.mp hi
rw [Nat.sub_add_cancel left_bound]
· -- left membership preservation
intro i hi -- hi : i ∈ Finset.Icc 1 (ℓ - 1)
rw [Finset.mem_Icc]
have ⟨left_bound, right_bound⟩ := Finset.mem_Icc.mp hi
-- ⊢ 0 ≤ i - 1 ∧ i - 1 ≤ ℓ₁ - 1
apply And.intro
· exact Nat.pred_le_pred left_bound
· exact Nat.pred_le_pred right_bound
· -- right membership preservation
intro j hj
rw [Finset.mem_Icc]
have ⟨left_bound, right_bound⟩ := Finset.mem_Icc.mp hj -- (0 ≤ j ∧ j ≤ ℓ₁ - 1)
-- ⊢ 1 ≤ j + 1 ∧ j + 1 ≤ ℓ - 1
apply And.intro
· exact Nat.le_add_of_sub_le left_bound
· rw [h_ℓ_eq]; rw [Nat.add_sub_cancel]; -- ⊢ j + 1 ≤ ℓ₁
have h_j_add_1_le_ℓ₁ : j + 1 ≤ ℓ₁ := by
calc j + 1 ≤ (ℓ₁ - 1) + 1 := by apply Nat.add_le_add_right; exact right_bound;
_ = ℓ₁ := by rw [Nat.sub_add_cancel]; omega;
exact h_j_add_1_le_ℓ₁
rw [h_sum_2]
have h_sum_3 : ∑ k ∈ Finset.Icc 0 (ℓ₁-1), getBit k (m) * 2 ^ (k+1)
= 2 * ∑ k ∈ Finset.Icc 0 (ℓ₁-1), getBit k (m) * 2 ^ k := by
calc
_ = ∑ k ∈ Finset.Icc 0 (ℓ₁-1), ((getBit k (m) * 2^k) * 2) := by
apply Finset.sum_congr rfl (fun k hk => by
rw [Finset.mem_Icc] at hk -- hk : 0 ≤ k ∧ k ≤ ℓ₁ - 1
have h_res : getBit k (m) * 2 ^ (k+1) = getBit k (m) * 2 ^ k * 2 := by
rw [Nat.pow_succ, ←mul_assoc]
exact h_res
)
_ = (∑ k ∈ Finset.Icc 0 (ℓ₁-1), getBit k (m) * 2 ^ k) * 2 := by rw [Finset.sum_mul]
_ = 2 * ∑ k ∈ Finset.Icc 0 (ℓ₁-1), getBit k (m) * 2 ^ k := by rw [mul_comm]
rw [h_sum_3]
rw [←h_m_repr]
conv =>
rhs
rw [←h_j_eq] | 2 | 24 | true | Applied verif. |
5 | Nat.getBit_of_binaryFinMapToNat | lemma getBit_of_binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary: ∀ j: Fin n, m j ≤ 1) :
∀ k: ℕ, Nat.getBit k (binaryFinMapToNat m h_binary).val
= if h_k: k < n then m ⟨k, by omega⟩ else 0 | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.univ",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Ne",
"module": "Init.Core"
},
... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.and_one_is_mod",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.mod_lt",
"module": "Init.Prelude"
},
{
"name": "Nat.ofNat_pos",
"module": "Mathlib.Data.Nat.Cast.Order.Ring"
},
{
"name": "gt_iff_lt",
"module": "Init.Core"
},
{
"name": "Na... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "Nat.binaryFinMapToNat",
"content": "def binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary : ∀ j: Fin n, m j ≤ 1) : Fin (2^n) :="
}
] | [
{
"name": "Nat.getBit_lt_2",
"content": "lemma getBit_lt_2 {k n : Nat} : getBit k n < 2"
},
{
"name": "Nat.getBit_eq_testBit",
"content": "lemma getBit_eq_testBit (k n : Nat) : getBit k n = if n.testBit k then 1 else 0"
},
{
"name": "Nat.getBit_zero_eq_zero",
"content": "lemma getBit... | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1
def binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary : ∀ j: Fin n, m j ≤ 1) : Fin (2^n) := | lemma getBit_of_binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary: ∀ j: Fin n, m j ≤ 1) :
∀ k: ℕ, Nat.getBit k (binaryFinMapToNat m h_binary).val
= if h_k: k < n then m ⟨k, by omega⟩ else 0 := | := by
-- We prove this by induction on `n`.
induction n with
| zero =>
intro k;
simp only [Nat.pow_zero, Fin.val_eq_zero, not_lt_zero', ↓reduceDIte]
exact getBit_zero_eq_zero
| succ n ih =>
-- Inductive step: Assume the property holds for `n`, prove it for `n+1`.
have h_lt: 2^n - 1 < 2^n := by
refine sub_one_lt ?_
exact Ne.symm (NeZero.ne' (2 ^ n))
intro k
dsimp [binaryFinMapToNat]
-- ⊢ (↑k).getBit (∑ j, 2 ^ ↑j * m j) = m k
rw [Fin.sum_univ_castSucc] -- split the msb
set prevSum := ∑ i: Fin n, (2 ^ i.castSucc.val) * (m i.castSucc)
let mPrev := fun i: Fin n => m i.castSucc
have h_getBit_prevSum := ih (m:=mPrev) (h_binary:=by exact fun j ↦ h_binary j.castSucc)
have h_prevSum_eq: prevSum = binaryFinMapToNat mPrev
(by exact fun j ↦ h_binary j.castSucc) := by rfl
set msbTerm := 2 ^ ((Fin.last n).val) * m (Fin.last n)
-- ⊢ (↑k).getBit (prevSum + msbTerm) = m k
have h_m_at_last: m ⟨n, by omega⟩ ≤ 1 := by exact h_binary (Fin.last n)
have h_sum_eq_xor: prevSum + msbTerm = prevSum ^^^ msbTerm := by
rw [sum_of_and_eq_zero_is_xor]
unfold msbTerm
interval_cases h_m_last_val: m ⟨n, by omega⟩
· simp only [Fin.last, h_m_last_val, mul_zero, Nat.and_zero]
· simp only [Fin.last, h_m_last_val, mul_one]
apply and_two_pow_eq_zero_of_getBit_0
have h_getBit_prevSum_at_n := getBit_of_lt_two_pow (k:=n) (n:=n) (a:=⟨prevSum, by omega⟩)
simp only [lt_self_iff_false, ↓reduceIte] at h_getBit_prevSum_at_n
rw [h_getBit_prevSum_at_n]
rw [h_sum_eq_xor, getBit_of_xor]
if h_k_eq: k = n then
rw [h_k_eq]
simp only [lt_add_iff_pos_right, zero_lt_one, ↓reduceDIte]
rw [h_prevSum_eq]
rw [getBit_of_lt_two_pow]
simp only [lt_self_iff_false, ↓reduceIte, zero_xor]
unfold msbTerm
-- ⊢ n.getBit (2 ^ ↑(Fin.last n) * m (Fin.last n)) = m ⟨n, ⋯⟩
interval_cases h_m_last_val: m ⟨n, by omega⟩
· -- ⊢ n.getBit (2 ^ ↑(Fin.last n) * m (Fin.last n)) = 0
rw [Fin.val_last, Fin.last]
rw [h_m_last_val, mul_zero]
exact getBit_zero_eq_zero
· -- ⊢ n.getBit (2 ^ ↑(Fin.last n) * m (Fin.last n)) = 1
simp only [Fin.last]
rw [h_m_last_val, mul_one]
rw [Nat.getBit_two_pow]
simp only [BEq.rfl, ↓reduceIte]
else
have hBitLhs := h_getBit_prevSum (k:=k)
simp only at hBitLhs
rw [h_prevSum_eq.symm] at hBitLhs
rw [hBitLhs]
if h_k_lt_n: k < n then
have h_k_lt_n_add_1: k < n + 1 := by omega
simp only [h_k_lt_n_add_1, ↓reduceDIte]
push_neg at h_k_eq
simp only [h_k_lt_n, ↓reduceDIte]
unfold msbTerm
interval_cases h_m_last_val: m ⟨n, by omega⟩
· simp only [Fin.last, h_m_last_val, mul_zero]
rw [Nat.getBit_zero_eq_zero, Nat.xor_zero]
rfl
· simp only [Fin.last, h_m_last_val, mul_one]
rw [Nat.getBit_two_pow]
simp only [beq_iff_eq]
simp only [h_k_eq.symm, ↓reduceIte, xor_zero]
rfl
else
have h_k_not_lt_n_add_1: ¬(k < n + 1) := by omega
have h_k_not_lt_n: ¬(k < n) := by omega
simp only [h_k_not_lt_n_add_1, h_k_not_lt_n, ↓reduceDIte, Nat.zero_xor]
unfold msbTerm
interval_cases h_m_last_val: m ⟨n, by omega⟩
· simp only [Fin.last, h_m_last_val, mul_zero]
exact getBit_zero_eq_zero
· simp only [Fin.last, h_m_last_val, mul_one]
rw [Nat.getBit_two_pow]
simp only [beq_iff_eq]
simp only [ite_eq_right_iff, one_ne_zero, imp_false, ne_eq]
omega | 4 | 104 | true | Applied verif. |
6 | ConcreteBinaryTower.towerEquiv_commutes_left_diff | lemma towerEquiv_commutes_left_diff (i d : ℕ) : ∀ r : ConcreteBTField i,
(AlgebraTower.algebraMap i (i+d) (by omega)) ((towerEquiv i).ringEquiv r) =
(towerEquiv (i+d)).ringEquiv ((AlgebraTower.algebraMap i (i+d) (by omega)) r) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "BT... | [
{
"name": "Ne.dite_eq_left_iff",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.add_one_sub_one",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.left_eq_add",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "RingHom.comp_id",
"module": "Mathlib.Algebra.Ring.Hom.Defs"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le
def join_via_add_smul (k : ℕ) (h_pos : k > 0) (hi_btf lo_btf : ConcreteBTField (k - 1)) :
ConcreteBTField k :=
end ConcreteBTFieldAlgebraConstruction
noncomputable section ConcreteMultilinearBasis
open Module
def basisSucc (k : ℕ) : Basis (Fin 2) (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
def powerBasisSucc (k : ℕ) :
PowerBasis (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
end ConcreteMultilinearBasis
section TowerEquivalence
open BinaryTower
noncomputable def towerEquiv_zero : RingEquiv (R:=GF(2)) (S:=ConcreteBTField 0) := {
toFun := fun x => if x = 0 then 0 else 1,
invFun := fun x => if x = 0 then 0 else 1,
left_inv := fun x => by admit /- proof elided -/
noncomputable def towerRingEquiv0 : BTField 0 ≃+* ConcreteBTField 0 :=
noncomputable def towerRingEquivFromConcrete0 : ConcreteBTField 0 ≃+* BTField 0 :=
noncomputable def towerRingHomForwardMap (k : ℕ) : ConcreteBTField k → BTField k :=
noncomputable def towerRingHomBackwardMap (k : ℕ) : BTField k → ConcreteBTField k :=
structure TowerEquivResult (k : ℕ) where
ringEquiv : ConcreteBTField k ≃+* BTField k
ringEquivForwardMapEq : ringEquiv = towerRingHomForwardMap k
noncomputable def towerEquiv (n : ℕ) : TowerEquivResult n := | lemma towerEquiv_commutes_left_diff (i d : ℕ) : ∀ r : ConcreteBTField i,
(AlgebraTower.algebraMap i (i+d) (by omega)) ((towerEquiv i).ringEquiv r) =
(towerEquiv (i+d)).ringEquiv ((AlgebraTower.algebraMap i (i+d) (by omega)) r) := | := by
-- If d = 0, then this is trivial
-- For d > 0 : let j = i+d
-- lhs of goal : right => 《 0, ringMap x 》 => up => 《 algMap 0 = 0, algMap (ringMap x) 》
-- rhs of goal : up => 《 0, algMap x 》 => right => 《 ringMap 0 = 0, ringMap (algMap x) 》
-- where both `algMap (ringMap x)` and `ringMap (algMap x)` are in `BTField (j-1)`
-- => Strategy : For each i => do induction upwards on d
change ∀ r : ConcreteBTField i,
(BinaryTower.towerAlgebraMap (l:=i) (r:=i+d) (h_le:=by omega)) ((towerEquiv i).ringEquiv r) =
(towerEquiv (i+d)).ringEquiv ((concreteTowerAlgebraMap i (i+d) (by omega)) r)
induction d using Nat.rec with
| zero =>
intro r
simp only [Nat.add_zero]
rw [BinaryTower.towerAlgebraMap_id, concreteTowerAlgebraMap_id]
rfl
| succ d' ih =>
intro r
letI instAbstractAlgebra : Algebra (BTField i) (BTField (i + d' + 1)) :=
binaryAlgebraTower (by omega)
let : Algebra (ConcreteBTField i) (ConcreteBTField (i + d')) :=
ConcreteBTFieldAlgebra (l:=i) (r:=i+d') (h_le:=by omega)
letI instConcreteAlgebra : Algebra (ConcreteBTField i) (ConcreteBTField (i + d' + 1)) :=
ConcreteBTFieldAlgebra (l:=i) (r:=i+d'+1) (h_le:=by omega)
change (algebraMap (R:=BTField i) (A:=BTField (i + d' + 1))) ((towerEquiv i).ringEquiv r) =
(towerEquiv (i + d' + 1)).ringEquiv ((algebraMap (R:=ConcreteBTField i)
(A:=ConcreteBTField (i + d' + 1))) r)
have h_concrete_algMap_eq_zero_x := algebraMap_eq_zero_x (i:=i) (j:=i+d'+1) (h_le:=by omega) r
simp only [Nat.add_one_sub_one] at h_concrete_algMap_eq_zero_x
rw [algebraMap, Algebra.algebraMap] at h_concrete_algMap_eq_zero_x
have h_abstract_algMap_eq_zero_x := BinaryTower.algebraMap_eq_zero_x (i:=i) (j:=i+d'+1)
(h_le:=by omega) ((towerEquiv i).ringEquiv r)
simp only [Nat.add_one_sub_one] at h_abstract_algMap_eq_zero_x
conv_lhs =>
rw! [h_abstract_algMap_eq_zero_x]
conv_rhs =>
rw [algebraMap, Algebra.algebraMap]
simp only [BTField.eq_1, CommRing.eq_1, BTFieldIsField.eq_1, instConcreteAlgebra]
rw! [h_concrete_algMap_eq_zero_x] -- split algebraMap
-- Now change `BinaryTowerAux (i + d' + 1)).fst` back to `BTField (i + d' + 1)`
-- for definitional equality, otherwise we can't `rw [ringEquivForwardMapEq]`
change (towerEquiv (i + d' + 1)).ringEquiv (join (h_pos:=by omega) 0
((algebraMap (ConcreteBTField i) (ConcreteBTField (i + d'))) r))
rw [(towerEquiv (i+d'+1)).ringEquivForwardMapEq]
-- now convert to BinaryTower.join_via_add_smul
rw [towerRingHomForwardMap_join (k:=i+d'+1) (h_pos:=by omega)]
simp only [Nat.add_one_sub_one]
-- ⊢ BinaryTower.join_via_add_smul ⋯ = BinaryTower.join_via_add_smul ⋯ =
rw [BinaryTower.join_eq_join_iff]
constructor
· rw [towerRingHomForwardMap_zero]
· let h := ih (r:=r)
change (BinaryTower.towerAlgebraMap (l:=i) (r:=i+d')
(h_le:=by omega)) ((towerEquiv i).ringEquiv r) =
towerRingHomForwardMap (i + d') ((concreteTowerAlgebraMap i (i + d') (by omega)) r)
rw [h]
rw [(towerEquiv (i+d')).ringEquivForwardMapEq] | 10 | 306 | false | Applied verif. |
7 | AdditiveNTT.intermediateNormVpoly_comp | omit [DecidableEq L] [DecidableEq 𝔽q] h_Fq_char_prime hF₂ hβ_lin_indep h_β₀_eq_1 in
theorem intermediateNormVpoly_comp (i : Fin ℓ) (k : Fin (ℓ - i + 1))
(l : Fin (ℓ - (i.val + k.val) + 1)) :
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) (k:=⟨k + l, by
simp only; omega⟩) =
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i+k, by omega⟩) (k:=⟨l, by
simp only; omega⟩)).comp (
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) (k:=⟨k, by
simp only; omega⟩)
) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Fin.cast_eq_self",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fin.coe_cast",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.coe_castSucc",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
}
] | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.intermedia... | [] | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X) | omit [DecidableEq L] [DecidableEq 𝔽q] h_Fq_char_prime hF₂ hβ_lin_indep h_β₀_eq_1 in
theorem intermediateNormVpoly_comp (i : Fin ℓ) (k : Fin (ℓ - i + 1))
(l : Fin (ℓ - (i.val + k.val) + 1)) :
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) (k:=⟨k + l, by
simp only; omega⟩) =
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i+k, by omega⟩) (k:=⟨l, by
simp only; omega⟩)).comp (
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) (k:=⟨k, by
simp only; omega⟩)
) := | := by
induction l using Fin.succRecOnSameFinType with
| zero =>
simp only [Fin.coe_ofNat_eq_mod, Nat.zero_mod, add_zero, Fin.eta, Fin.zero_eta]
have h_eq_X : intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i + ↑k, by omega⟩ 0 = X := by
simp only [intermediateNormVpoly, Fin.coe_ofNat_eq_mod, Nat.zero_mod, Fin.foldl_zero]
simp only [h_eq_X, X_comp]
| succ j jh p =>
-- Inductive case: l = j + 1
-- Following the pattern from concreteTowerAlgebraMap_assoc:
-- A = |i| --- (k) --- |i+k| --- (j+1) --- |i+k+j+1|
-- Proof: A = (j+1) ∘ (k) (direct) = ((1) ∘ (j)) ∘ (k) (succ decomposition)
-- = (1) ∘ ((j) ∘ (k)) (associativity) = (1) ∘ (jk) (induction hypothesis)
unfold intermediateNormVpoly
-- First, rewrite to get the right form for Fin.foldl_succ
-- We need Fin.foldl (k + j + 1) which equals Fin.foldl ((k + j) + 1)
simp only
have h_j_add_1_val: (j + 1).val = j.val + 1 := by
rw [Fin.val_add_one']
omega
simp_rw [h_j_add_1_val]
simp_rw [←Nat.add_assoc (n:=k.val) (m:=j.val) (k:=1)]
rw [Fin.foldl_succ_last, Fin.foldl_succ_last]
simp only [Fin.cast_eq_self, Fin.coe_cast, Fin.val_last, Fin.coe_castSucc]
simp_rw [←Nat.add_assoc (n:=i.val) (m:=k.val) (k:=j.val)]
rw [comp_assoc]
-- ⊢ qMap (i := i + k + j)(...) = qMap (i := i + k + j)(...)
congr | 5 | 38 | false | Applied verif. |
8 | AdditiveNTT.inductive_rec_form_W_comp | omit h_Fq_char_prime hF₂ in
lemma inductive_rec_form_W_comp (i : Fin r) (h_i_add_1 : i + 1 < r)
(h_prev_linear_map : IsLinearMap (R := 𝔽q) (M := L[X]) (M₂ := L[X])
(f := fun inner_p ↦ (W 𝔽q β i).comp inner_p))
: ∀ p: L[X], (W 𝔽q β (i + 1)).comp p =
((W 𝔽q β i).comp p) ^ Fintype.card 𝔽q -
C (eval (β i) (W 𝔽q β i)) ^ (Fintype.card 𝔽q - 1) * ((W 𝔽q β i).comp p) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Fact.out",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Fin.le_zero_iff'",
"module": "Mathlib.Data.Fin.SuccPred"
},
{
"name": "LinearIndependent.injective",
"module": "Mathlib.LinearAlgebra.LinearIndependent.Defs"
},
{
"name": "Nat.not_lt_zero",
"module": "Ini... | [
{
"name": "Fin.lt_succ'",
"content": "lemma Fin.lt_succ' (a : Fin r) (h_a_add_1 : a + 1 < r) : a < a + 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
},
{
"name": "Fin.le_succ",
"content": "lemma F... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.algEquivAevalXSubC",
... | [
{
"name": "AdditiveNTT.βᵢ_not_in_Uᵢ",
"content": "lemma βᵢ_not_in_Uᵢ (i : Fin r) :\n β i ∉ U 𝔽q β i"
},
{
"name": "AdditiveNTT.root_U_lift_down",
"content": "omit [Fintype L] [DecidableEq L] [Fintype 𝔽q] h_Fq_char_prime in\ntheorem root_U_lift_down\n (i : Fin r) (h_i_add_1 : i + 1 < r) (a ... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
@[simps!]
noncomputable def algEquivAevalXSubC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := | omit h_Fq_char_prime hF₂ in
lemma inductive_rec_form_W_comp (i : Fin r) (h_i_add_1 : i + 1 < r)
(h_prev_linear_map : IsLinearMap (R := 𝔽q) (M := L[X]) (M₂ := L[X])
(f := fun inner_p ↦ (W 𝔽q β i).comp inner_p))
: ∀ p: L[X], (W 𝔽q β (i + 1)).comp p =
((W 𝔽q β i).comp p) ^ Fintype.card 𝔽q -
C (eval (β i) (W 𝔽q β i)) ^ (Fintype.card 𝔽q - 1) * ((W 𝔽q β i).comp p) := | := by
intro p
set W_i := W 𝔽q β i
set q := Fintype.card 𝔽q
set v := W_i.eval (β i)
-- First, we must prove that v is non-zero to use its inverse.
have hv_ne_zero : v ≠ 0 := by
unfold v W_i
exact Wᵢ_eval_βᵢ_neq_zero 𝔽q β i
-- Proof flow:
-- `Wᵢ₊₁(X) = ∏_{c ∈ 𝔽q} (Wᵢ ∘ (X - c • βᵢ))` -- from W_prod_comp_decomposition
-- `= ∏_{c ∈ 𝔽q} (Wᵢ(X) - c • Wᵢ(βᵢ))` -- linearity of Wᵢ
-- `= ∏_{c ∈ 𝔽q} (Wᵢ(X) - c • v)`
-- `= v² ∏_{c ∈ 𝔽q} (v⁻¹ • Wᵢ(X) - c)`
-- `= v² (v⁻² • Wᵢ(X)² - v⁻¹ • Wᵢ(X))` => FLT (prod_X_sub_C_eq_X_pow_card_sub_X_in_L)
-- `= Wᵢ(X)² - v • Wᵢ(X)` => Q.E.D
have h_scalar_smul_eq_C_v_mul: ∀ s: L, ∀ p: L[X], s • p = C s * p := by
intro s p
exact smul_eq_C_mul s
have h_v_smul_v_inv_eq_one: v • v⁻¹ = 1 := by
simp only [smul_eq_mul]
exact CommGroupWithZero.mul_inv_cancel v hv_ne_zero
have h_v_mul_v_inv_eq_one: v * v⁻¹ = 1 := by
exact h_v_smul_v_inv_eq_one
-- The main proof using a chain of equalities (the `calc` block).
calc
(W 𝔽q β (i + 1)).comp p
_ = (∏ c: 𝔽q, (W_i).comp (X - C (c • β i))).comp p := by
have h_res := W_prod_comp_decomposition 𝔽q β (i+1) (by
apply Fin.mk_lt_of_lt_val
rw [Fin.val_add_one' (a := i) (h_a_add_1 := h_i_add_1), Nat.zero_mod]
omega
)
rw [h_res]
simp only [add_sub_cancel_right]
rfl
-- Step 2: Apply the linearity property of Wᵢ as a polynomial.
_ = (∏ c: 𝔽q, (W_i - C (W_i.eval (c • β i)))).comp p := by
congr
funext c
-- We apply the transformation inside the product for each element `c`.
-- apply Finset.prod_congr rfl
-- ⊢ W_i.comp (X - C (c • β i)) = W_i - C (eval (c • β i) W_i)
exact comp_sub_C_of_linear_eval (p := W_i) (h_lin := h_prev_linear_map) (a := (c • β i))
-- Step 3: Apply the linearity of Wᵢ's *evaluation map* to the constant term.
-- Hypothesis: `h_prev_linear_map.map_smul`
_ = (∏ c: 𝔽q, (W_i - C (c • v))).comp p := by
congr
funext c
-- ⊢ W_i - C (eval (c • β i) W_i) = W_i - C (c • v)
congr
-- ⊢ eval (c • β i) W_i = c • v
-- Use the linearity of the evaluation map, not the composition map
have h_eval_linear := Polynomial.linear_map_of_comp_to_linear_map_of_eval (f := (W 𝔽q β i))
(h_f_linear := h_prev_linear_map)
exact h_eval_linear.map_smul c (β i)
-- Step 4: Perform the final algebraic transformation.
_ = (C (v^q) * (∏ c: 𝔽q, (C (v⁻¹) * W_i - C (algebraMap 𝔽q L c)))).comp p := by
congr
calc
_ = ∏ c: 𝔽q, (v • (v⁻¹ • W_i - C (algebraMap 𝔽q L c))) := by
apply Finset.prod_congr rfl
intro c _
rw [smul_sub]
-- ⊢ W_i - C (c • v) = v • v⁻¹ • W_i - v • C ((algebraMap 𝔽q L) c)
rw [smul_C, smul_eq_mul, map_mul]
rw [←smul_assoc]
rw [h_v_smul_v_inv_eq_one]
rw [one_smul]
rw [sub_right_inj]
-- ⊢ C (c • v) = C v * C ((algebraMap 𝔽q L) c)
rw [←C_mul]
-- ⊢ C (c • v) = C (v * (algebraMap 𝔽q L) c)
have h_c_smul_v: c • v = (algebraMap 𝔽q L c) • v := by
exact algebra_compatible_smul L c v
rw [h_c_smul_v]
rw [mul_comm]
rw [smul_eq_mul]
_ = ∏ c: 𝔽q, (C v * (v⁻¹ • W_i - C (algebraMap 𝔽q L c))) := by
apply Finset.prod_congr rfl
intro c _
rw [h_scalar_smul_eq_C_v_mul]
_ = C (v^q) * (∏ c: 𝔽q, (C v⁻¹ * W_i - C (algebraMap 𝔽q L c))) := by
-- rw [Finset.prod_mul_distrib]
-- rw [Finset.prod_const, Finset.card_univ]
rw [Finset.prod_mul_distrib]
conv_lhs =>
enter [2]
enter [2]
rw [h_scalar_smul_eq_C_v_mul]
congr
-- ⊢ ∏ (x: 𝔽q), C v = C (v ^ q)
rw [Finset.prod_const, Finset.card_univ]
unfold q
exact Eq.symm C_pow
_ = (C (v^q) * ((C v⁻¹ * W_i)^q - (C v⁻¹ * W_i))).comp p := by
congr
-- ⊢ ∏ c, (C v⁻¹ * W_i - C ((algebraMap 𝔽q L) c)) = (C v⁻¹ * W_i) ^ q - C v⁻¹ * W_i
rw [Polynomial.prod_poly_sub_C_eq_poly_pow_card_sub_poly_in_L (p := C v⁻¹ * W_i)]
_ = (C (v^q) * C (v⁻¹^q) * W_i^q - C (v^q) * C v⁻¹ * W_i).comp p := by
congr
rw [mul_sub]
conv_lhs =>
rw [mul_pow, ←mul_assoc, ←mul_assoc, ←C_pow]
_ = (W_i^q - C (v^(q-1)) * W_i).comp p := by
congr
· rw [←C_mul, ←mul_pow, h_v_mul_v_inv_eq_one, one_pow, C_1, one_mul]
· rw [←C_mul]
have h_v_pow_q_minus_1: v^q * v⁻¹ = v^(q-1) := by
rw [pow_sub₀ (a := v) (m := q) (n := 1) (ha := hv_ne_zero) (h := by exact NeZero.one_le)]
-- ⊢ v ^ q * v⁻¹ = v ^ q * (v ^ 1)⁻¹
congr
norm_num
rw [h_v_pow_q_minus_1]
_ = (W_i^q - C (eval (β i) W_i) ^ (q - 1) * W_i).comp p := by
simp only [map_pow, W_i, q, v]
_ = (W_i^q).comp p - (C (eval (β i) W_i) ^ (q - 1) * W_i).comp p := by
rw [sub_comp]
_ = (W_i.comp p)^q - (C (eval (β i) W_i) ^ (q - 1)) * (W_i.comp p) := by
rw [pow_comp, mul_comp]
conv_lhs =>
rw [pow_comp]
rw [C_comp (a := (eval (β i) W_i)) (p := p)] | 6 | 229 | false | Applied verif. |
9 | AdditiveNTT.odd_index_intermediate_novel_basis_decomposition | lemma odd_index_intermediate_novel_basis_decomposition
(i : Fin ℓ) (j : Fin (2 ^ (ℓ - i - 1))) :
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ ⟨j * 2 + 1, by
apply mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
⟩ = X * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le j (ℓ-i-1) (ℓ-(i+1)) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Polynomial.comp_assoc",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fin.foldl_succ",
"module": "Init.Data.Fin.Fol... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "getBit_eq_succ_getBit_of_mul_two_add_one",
"content": "lemma getBit_eq_succ_getBit_of_mul_two_add_one {n k : ℕ} : getBit (k+1) (2*n + 1) = get... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.intermedia... | [
{
"name": "AdditiveNTT.Polynomial.foldl_comp",
"content": "omit [Fintype L] [DecidableEq L] in\ntheorem Polynomial.foldl_comp (n : ℕ) (f : Fin n → L[X]) : ∀ initInner initOuter: L[X],\n Fin.foldl (n:=n) (fun acc j => (f j).comp acc) (initOuter.comp initInner)\n = (Fin.foldl (n:=n) (fun acc j => (f j).... | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X)
noncomputable def intermediateNovelBasisX (i : Fin (ℓ + 1)) (j : Fin (2 ^ (ℓ - i))) : L[X] :=
(Finset.univ: Finset (Fin (ℓ - i)) ).prod (fun k =>
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate i (k:=⟨k, by admit /- proof elided -/
⟩)) ^ (Nat.getBit k j)) | lemma odd_index_intermediate_novel_basis_decomposition
(i : Fin ℓ) (j : Fin (2 ^ (ℓ - i - 1))) :
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ ⟨j * 2 + 1, by
apply mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨1, by omega⟩ (by omega) (by omega)
⟩ = X * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le j (ℓ-i-1) (ℓ-(i+1)) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩) := | := by
unfold intermediateNovelBasisX
rw [prod_comp]
-- ∏ k ∈ Fin (ℓ - i), (Wₖ⁽ⁱ⁾(X))^((2j₊₁)ₖ)
-- = X * ∏ k ∈ Fin (ℓ - (i+1)), (Wₖ⁽ⁱ⁺¹⁾(X))^((j)ₖ) ∘ q⁽ⁱ⁾(X)
simp only [pow_comp]
conv_rhs =>
enter [2]
enter [2, x, 1]
rw [intermediateNormVpoly_comp_qmap_helper 𝔽q β h_ℓ_add_R_rate
⟨i, by omega⟩ ⟨x, by simp only; omega⟩]
-- ⊢ ∏ x, intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, ⋯⟩ x ^ Nat.getBit (↑x) (↑j * 2 + 1) =
-- X * ∏ x, intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, ⋯⟩ ⟨↑x + 1, ⋯⟩ ^ Nat.getBit ↑x ↑j
set fleft := fun x : Fin (ℓ - ↑i) =>
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩
⟨x, by simp only; omega⟩ ^ Nat.getBit (↑x) (↑j * 2 + 1)
have h_n_shift: ℓ - (↑i + 1) + 1 = ℓ - ↑i := by omega
have h_fin_n_shift: Fin (ℓ - (↑i + 1) + 1) = Fin (ℓ - ↑i) := by
rw [h_n_shift]
have h_left_prod_shift :=
Fin.prod_univ_succ (M:=L[X]) (n:=ℓ - (↑i + 1)) (f:=fun x => fleft ⟨x, by omega⟩)
have h_lhs_prod_eq: ∏ x : Fin (ℓ - ↑i),
fleft x = ∏ x : Fin (ℓ - (↑i + 1) + 1), fleft ⟨x, by omega⟩ := by
exact Eq.symm (Fin.prod_congr' fleft h_n_shift)
rw [←h_lhs_prod_eq] at h_left_prod_shift
rw [h_left_prod_shift]
have fleft_0_eq_X: fleft ⟨(0: Fin (ℓ - (↑i + 1) + 1)), by omega⟩ = X := by
unfold fleft
simp only
have h_exp: Nat.getBit (0: Fin (ℓ - (↑i + 1) + 1)) (↑j * 2 + 1) = 1 := by
simp only [Fin.coe_ofNat_eq_mod, Nat.zero_mod]
unfold Nat.getBit
simp only [Nat.shiftRight_zero, Nat.and_one_is_mod, Nat.mul_add_mod_self_right, Nat.mod_succ]
rw [h_exp]
simp only [pow_one, Fin.coe_ofNat_eq_mod, Nat.zero_mod]
unfold intermediateNormVpoly
simp only [Fin.foldl_zero]
rw [fleft_0_eq_X]
congr -- apply Finset.prod_congr rfl
funext x
simp only [Fin.val_succ]
unfold fleft
simp only
have h_exp_eq: Nat.getBit (↑x + 1) (↑j * 2 + 1) = Nat.getBit ↑x ↑j := by
have h_num_eq: j.val * 2 = 2 * j.val := by omega
rw [h_num_eq]
apply Nat.getBit_eq_succ_getBit_of_mul_two_add_one (k:=↑x) (n:=↑j)
rw [h_exp_eq] | 5 | 50 | false | Applied verif. |
10 | AdditiveNTT.finToBinaryCoeffs_sDomainToFin | omit h_β₀_eq_1 in
lemma finToBinaryCoeffs_sDomainToFin (i : Fin r) (h_i : i < ℓ + R_rate)
(x : sDomain 𝔽q β h_ℓ_add_R_rate i) :
let pointFinIdx := (sDomainToFin 𝔽q β h_ℓ_add_R_rate i h_i) x
finToBinaryCoeffs 𝔽q (i := i) (idx :=pointFinIdx) =
(sDomain_basis 𝔽q β
h_ℓ_add_R_rate i h_i).repr x | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (i : Fin r) : L[X] :=\n C (1 / (W 𝔽q β i).eval (β i)) * W 𝔽q β i"
},
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : ... | [
{
"name": "Fintype.card_le_one_iff_subsingleton",
"module": "Mathlib.Data.Fintype.EquivFin"
},
{
"name": "Fintype.card_units",
"module": "Mathlib.Data.Fintype.Units"
},
{
"name": "Nat.le_of_eq",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Subsingleton.elim",
"module": "... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "getBit_of_binaryFinMapToNat",
"content": "lemma getBit_of_binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary: ∀ j: Fin n, m j ≤ 1) :\n ∀ k... | [
{
"name": "AdditiveNTT.sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\n AdditiveNTT.normalizedW_is_additive 𝔽q β i\n Submodule.map (polyEvalLinearMap... | [
{
"name": "AdditiveNTT.𝔽q_element_eq_zero_or_eq_one",
"content": "omit h_Fq_char_prime in\nlemma 𝔽q_element_eq_zero_or_eq_one : ∀ c: 𝔽q, c = 0 ∨ c = 1"
}
] | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=
let W_i_norm := normalizedW 𝔽q β i
let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=
AdditiveNTT.normalizedW_is_additive 𝔽q β i
Submodule.map (polyEvalLinearMap W_i_norm h_W_i_norm_is_additive)
(U 𝔽q β ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩)
def sBasis (i : Fin r) (h_i : i < ℓ + R_rate) : Fin (ℓ + R_rate - i) → L :=
fun k => β ⟨i + k.val, by admit /- proof elided -/
⟩
noncomputable def sDomain_basis (i : Fin r) (h_i : i < ℓ + R_rate) :
Basis (Fin (ℓ + R_rate - i)) 𝔽q (
sDomain 𝔽q β h_ℓ_add_R_rate i) :=
noncomputable section DomainBijection
def splitPointIntoCoeffs (i : Fin r) (h_i : i < ℓ + R_rate)
(x : sDomain 𝔽q β h_ℓ_add_R_rate i) :
Fin (ℓ + R_rate - i.val) → ℕ := fun j =>
if ((sDomain_basis 𝔽q β
h_ℓ_add_R_rate i h_i).repr x j = 0) then
0 else 1
noncomputable def sDomainToFin (i : Fin r) (h_i : i < ℓ + R_rate)
(x : sDomain 𝔽q β h_ℓ_add_R_rate i) :
Fin (2^(ℓ + R_rate - i.val)) :=
def finToBinaryCoeffs (i : Fin r) (idx : Fin (2 ^ (ℓ + R_rate - i.val))) :
Fin (ℓ + R_rate - i.val) → 𝔽q := fun j =>
if (Nat.getBit (k:=j) (n:=idx)) = 1 then (1 : 𝔽q) else (0 : 𝔽q) | omit h_β₀_eq_1 in
lemma finToBinaryCoeffs_sDomainToFin (i : Fin r) (h_i : i < ℓ + R_rate)
(x : sDomain 𝔽q β h_ℓ_add_R_rate i) :
let pointFinIdx := | := (sDomainToFin 𝔽q β h_ℓ_add_R_rate i h_i) x
finToBinaryCoeffs 𝔽q (i := i) (idx :=pointFinIdx) =
(sDomain_basis 𝔽q β
h_ℓ_add_R_rate i h_i).repr x:= by
simp only
ext j
-- Unfold the definitions to get to the core logic
dsimp [sDomainToFin, finToBinaryCoeffs, splitPointIntoCoeffs]
-- `Nat.getBit` is the inverse of `Nat.binaryFinMapToNat`
rw [Nat.getBit_of_binaryFinMapToNat]
-- Let `c` be the j-th coefficient we are considering
set c := (sDomain_basis 𝔽q β
h_ℓ_add_R_rate i h_i).repr x j
-- Since the field has card 2, `c` must be 0 or 1
have hc : c = 0 ∨ c = 1 := by exact 𝔽q_element_eq_zero_or_eq_one 𝔽q c
-- exact ((Fintype.card_eq_two_iff _).mp h_Fq_card_eq_2).right c
-- We can now split on whether c is 0 or 1
rcases hc with h_c_zero | h_c_one
· -- Case 1: The coefficient is 0
simp only [Fin.is_lt, ↓reduceDIte, Fin.eta, h_c_zero, ite_eq_right_iff, one_ne_zero, imp_false,
ne_eq]
unfold splitPointIntoCoeffs
simp only [ite_eq_right_iff, zero_ne_one, imp_false, Decidable.not_not]
omega
· -- Case 2: The coefficient is 1
simp only [Fin.is_lt, ↓reduceDIte, Fin.eta, h_c_one, ite_eq_left_iff, zero_ne_one, imp_false,
Decidable.not_not]
unfold splitPointIntoCoeffs
simp only [ite_eq_right_iff, zero_ne_one, imp_false, ne_eq]
change ¬(c) = 0
rw [h_c_one]
exact one_ne_zero | 5 | 84 | false | Applied verif. |
11 | AdditiveNTT.sDomain_eq_image_of_upper_span | lemma sDomain_eq_image_of_upper_span (i : Fin r) (h_i : i < ℓ + R_rate) :
let V_i := Submodule.span 𝔽q (Set.range (sBasis β h_ℓ_add_R_rate i h_i))
let W_i_map := polyEvalLinearMap (normalizedW 𝔽q β i)
(normalizedW_is_additive 𝔽q β i)
sDomain 𝔽q β h_ℓ_add_R_rate i
= Submodule.map W_i_map V_i | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import Mathlib.Tactic",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (i : Fin r) : L[X] :=\n C (1 / (W 𝔽q β i).eval (β i)) * W 𝔽q β i"
},
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : ... | [
{
"name": "Fin.mk_le_of_le_val",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.mk_lt_of_lt_val",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Nat.lt_sub_of_add_lt",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "normalizedWᵢ_vanishing",
"content": "lemma normalizedWᵢ_vanishing (i : Fin r) :\n ∀ u ∈ U 𝔽q β i, (normalizedW 𝔽q β i).eval u = 0"
},
{... | [
{
"name": "AdditiveNTT.sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\n AdditiveNTT.normalizedW_is_additive 𝔽q β i\n Submodule.map (polyEvalLinearMap... | [
{
"name": "AdditiveNTT.sBasis_range_eq",
"content": "omit [NeZero r] [Field L] [Fintype L] [DecidableEq L] [Field 𝔽q] [Algebra 𝔽q L] in\nlemma sBasis_range_eq (i : Fin r) (h_i : i < ℓ + R_rate) :\n β '' Set.Ico i ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩\n = Set.range (sBasis β h_ℓ_add_R_rate i h_i)"
}
] | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=
let W_i_norm := normalizedW 𝔽q β i
let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=
AdditiveNTT.normalizedW_is_additive 𝔽q β i
Submodule.map (polyEvalLinearMap W_i_norm h_W_i_norm_is_additive)
(U 𝔽q β ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩)
def sBasis (i : Fin r) (h_i : i < ℓ + R_rate) : Fin (ℓ + R_rate - i) → L :=
fun k => β ⟨i + k.val, by admit /- proof elided -/
⟩ | lemma sDomain_eq_image_of_upper_span (i : Fin r) (h_i : i < ℓ + R_rate) :
let V_i := | := Submodule.span 𝔽q (Set.range (sBasis β h_ℓ_add_R_rate i h_i))
let W_i_map := polyEvalLinearMap (normalizedW 𝔽q β i)
(normalizedW_is_additive 𝔽q β i)
sDomain 𝔽q β h_ℓ_add_R_rate i
= Submodule.map W_i_map V_i :=
by
-- Proof: U_{ℓ+R} is the direct sum of Uᵢ and Vᵢ.
-- Any x in U_{ℓ+R} can be written as u + v where u ∈ Uᵢ and v ∈ Vᵢ.
-- Ŵᵢ(x) = Ŵᵢ(u+v) = Ŵᵢ(u) + Ŵᵢ(v) = 0 + Ŵᵢ(v) = Ŵᵢ(v).
-- So the image of U_{ℓ+R} is the same as the image of Vᵢ.
-- Define V_i and W_i_map for use in the proof
set V_i := Submodule.span 𝔽q (Set.range (sBasis β h_ℓ_add_R_rate i h_i))
set W_i_map := polyEvalLinearMap (normalizedW 𝔽q β i)
(normalizedW_is_additive 𝔽q β i)
-- First, show that U_{ℓ+R} = U_i ⊔ V_i (direct sum)
have h_span_supremum_decomposition : U 𝔽q β ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩
= U 𝔽q β i ⊔ V_i := by
unfold U
-- U_{ℓ+R} is the span of {β₀, ..., β_{ℓ+R-1}}
-- U_i is the span of {β₀, ..., β_{i-1}}
-- V_i is the span of {β_i, ..., β_{ℓ+R-1}}
have h_ico : Set.Ico 0 ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩
= Set.Ico 0 i ∪ Set.Ico i ⟨ℓ + R_rate, h_ℓ_add_R_rate⟩ := by
ext k
simp only [Set.mem_Ico, Fin.zero_le, true_and, Set.mem_union]
constructor
· intro h
by_cases hk : k < i
· left; omega
· right; exact ⟨Nat.le_of_not_lt hk, by omega⟩
· intro h
cases h with
| inl h => exact Fin.lt_trans h h_i
| inr h => exact h.2
rw [h_ico, Set.image_union, Submodule.span_union]
congr
-- ⊢ β '' Set.Ico i (ℓ + R_rate)
-- = Set.range (sBasis β (h_ℓ_add_R_rate:=h_ℓ_add_R_rate) i h_i)
-- Now how that the image of Set.Ico i (ℓ + R_rate)
-- (from the definition of U_{ℓ+R}) is the same as V_i
rw [sBasis_range_eq β h_ℓ_add_R_rate i h_i]
-- Now show that the image of U_{ℓ+R} under W_i_map is the same as the image of V_i
rw [sDomain, h_span_supremum_decomposition, Submodule.map_sup]
-- The image of U_i under W_i_map is {0} because W_i vanishes on U_i
have h_U_i_image : Submodule.map W_i_map (U 𝔽q β i) = ⊥ := by
-- Show that any element in the image is 0
apply (Submodule.eq_bot_iff _).mpr
intro x hx
-- x ∈ Submodule.map W_i_map (U 𝔽q β i) means x = W_i_map(y) for some y ∈ U_i
rcases Submodule.mem_map.mp hx with ⟨y, hy, rfl⟩
-- Show that W_i_map y = 0 for any y ∈ U_i
have h_eval_zero : (normalizedW 𝔽q β i).eval y = 0 :=
normalizedWᵢ_vanishing 𝔽q β i y hy
exact h_eval_zero
-- Combine the results: ⊥ ⊔ V = V
rw [h_U_i_image]
rw [bot_sup_eq] | 11 | 81 | false | Applied verif. |
12 | AdditiveNTT.initial_tiled_coeffs_correctness | omit [DecidableEq 𝔽q] hF₂ in
lemma initial_tiled_coeffs_correctness (h_ℓ : ℓ ≤ r) (a : Fin (2 ^ ℓ) → L) :
let b: Fin (2^(ℓ + R_rate)) → L := tileCoeffs a
additiveNTTInvariant 𝔽q β h_ℓ_add_R_rate b a (i := ⟨ℓ, by omega⟩) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs",
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Fintype.card_pos",
"module": "Mathlib.Data.Fintype.Card"
},
{
"name": "Polynomial.C_1",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Polynomial.C_comp",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "Polynomial.C_mul",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "W_linear_comp_decomposition",
"content": "omit hF₂ in\ntheorem W_linear_comp_decomposition (i : Fin r) (h_i_add_1 : i + 1 < r) :\n ∀ p: L[X... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.qCompositi... | [
{
"name": "AdditiveNTT.qMap_comp_normalizedW",
"content": "lemma qMap_comp_normalizedW (i : Fin r) (h_i_add_1 : i + 1 < r) :\n (qMap 𝔽q β i).comp (normalizedW 𝔽q β i) = normalizedW 𝔽q β (i + 1)"
},
{
"name": "AdditiveNTT.qCompositionChain_eq_foldl",
"content": "lemma qCompositionChain_eq_fol... | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable def qCompositionChain (i : Fin r) : L[X] :=
match i with
| ⟨0, _⟩ => X
| ⟨k + 1, h_k_add_1⟩ => (qMap 𝔽q β ⟨k, by admit /- proof elided -/
⟩).comp (qCompositionChain ⟨k, by admit /- proof elided -/
⟩)
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X)
noncomputable def intermediateNovelBasisX (i : Fin (ℓ + 1)) (j : Fin (2 ^ (ℓ - i))) : L[X] :=
(Finset.univ: Finset (Fin (ℓ - i)) ).prod (fun k =>
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate i (k:=⟨k, by admit /- proof elided -/
⟩)) ^ (Nat.getBit k j))
noncomputable def intermediateEvaluationPoly (i : Fin (ℓ + 1))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i))), C (coeffs ⟨j, by admit /- proof elided -/
⟩) *
(intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate i ⟨j, by admit /- proof elided -/
⟩)
end IntermediateStructures
section AlgorithmCorrectness
noncomputable def evaluationPointω (i : Fin (ℓ + 1))
(x : Fin (2 ^ (ℓ + R_rate - i))) : L :=
∑ (⟨k, hk⟩: Fin (ℓ + R_rate - i)),
if Nat.getBit k x.val = 1 then
(normalizedW 𝔽q β ⟨i, by admit /- proof elided -/
⟩).eval (β ⟨i + k, by admit /- proof elided -/
⟩)
else
0
def tileCoeffs (a : Fin (2 ^ ℓ) → L) : Fin (2^(ℓ + R_rate)) → L :=
fun v => a (Fin.mk (v.val % (2^ℓ)) (Nat.mod_lt v.val (pow_pos (zero_lt_two) ℓ)))
def coeffsBySuffix (a : Fin (2 ^ ℓ) → L) (i : Fin (ℓ + 1)) (v : Fin (2 ^ i.val)) :
Fin (2 ^ (ℓ - i)) → L :=
fun ⟨j, hj⟩ => by admit /- proof elided -/
def additiveNTTInvariant (evaluation_buffer : Fin (2 ^ (ℓ + R_rate)) → L)
(original_coeffs : Fin (2 ^ ℓ) → L) (i : Fin (ℓ + 1)) : Prop :=
∀ (j : Fin (2^(ℓ + R_rate))),
let u_b_v := j.val
let v: Fin (2^i.val) := ⟨Nat.getLowBits i.val u_b_v, by admit /- proof elided -/
⟩
let u_b := u_b_v / (2^i.val)
have h_u_b : u_b = u_b_v / (2^i.val) := by admit /- proof elided -/ | omit [DecidableEq 𝔽q] hF₂ in
lemma initial_tiled_coeffs_correctness (h_ℓ : ℓ ≤ r) (a : Fin (2 ^ ℓ) → L) :
let b: Fin (2^(ℓ + R_rate)) → L := | := tileCoeffs a
additiveNTTInvariant 𝔽q β h_ℓ_add_R_rate b a (i := ⟨ℓ, by omega⟩) := by
unfold additiveNTTInvariant
simp only
intro j
unfold coeffsBySuffix
simp only [tileCoeffs, evaluationPointω, intermediateEvaluationPoly, Fin.eta]
have h_ℓ_sub_ℓ: 2^(ℓ - ℓ) = 1 := by norm_num
set f_right: Fin (2^(ℓ - ℓ)) → L[X] :=
fun ⟨x, hx⟩ => C (a ⟨↑x <<< ℓ ||| Nat.getLowBits ℓ (↑j), by
simp only [tsub_self, pow_zero, Nat.lt_one_iff] at hx
simp only [hx, Nat.zero_shiftLeft, Nat.zero_or]
exact Nat.getLowBits_lt_two_pow (numLowBits:=ℓ) (n:=j.val)
⟩) * intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨ℓ, by omega⟩ ⟨x, by omega⟩
have h_sum_right : ∑ (x: Fin (2^(ℓ - ℓ))), f_right x =
C (a ⟨Nat.getLowBits ℓ (↑j), by exact Nat.getLowBits_lt_two_pow ℓ⟩) *
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨ℓ, by omega⟩ 0 := by
have h_sum_eq := Fin.sum_congr' (b:=2^(ℓ - ℓ)) (a:=1) (f:=f_right) (by omega)
rw [←h_sum_eq]
rw [Fin.sum_univ_one]
unfold f_right
simp only [Fin.isValue, Fin.cast_zero, Fin.coe_ofNat_eq_mod, tsub_self, pow_zero,
Nat.zero_mod, Nat.zero_shiftLeft, Nat.zero_or]
congr
rw [h_sum_right]
set f_left: Fin (ℓ + R_rate - ℓ) → L := fun x =>
if Nat.getBit (x.val) (j.val / 2 ^ ℓ) = 1 then
eval (β ⟨ℓ + x.val, by omega⟩) (normalizedW 𝔽q β ⟨ℓ, by omega⟩)
else 0
simp only [eval_mul, eval_C]
have h_eval : eval (Finset.univ.sum f_left) (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate
⟨ℓ, by omega⟩ 0) = 1 := by
have h_base_novel_basis := base_intermediateNovelBasisX 𝔽q β
h_ℓ_add_R_rate ⟨ℓ, by exact Nat.lt_two_pow_self⟩
simp only [intermediateNovelBasisX, Fin.coe_ofNat_eq_mod, tsub_self, pow_zero,
Nat.zero_mod]
set f_inner : Fin (ℓ - ℓ) → L[X] := fun x => intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate
⟨ℓ, by omega⟩ ⟨x, by simp only; omega⟩ ^ Nat.getBit (x.val) 0
have h_sum_eq := Fin.prod_congr' (b:=ℓ - ℓ) (a:=0) (f:=f_inner) (by omega)
simp_rw [←h_sum_eq, Fin.prod_univ_zero]
simp only [eval_one]
rw [h_eval, mul_one]
simp only [Nat.getLowBits_eq_mod_two_pow] | 14 | 134 | false | Applied verif. |
13 | MlPoly.mobius_apply_zeta_apply_eq_id | theorem mobius_apply_zeta_apply_eq_id (n : ℕ) [NeZero n] (r : Fin n) (l : Fin (r.val + 1))
(v : Vector R (2 ^ n)) : lagrangeToMono_segment n r l (monoToLagrange_segment n r l v) = v | ArkLib | ArkLib/Data/MlPoly/Basic.lean | [
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.List.Lemmas",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Vector.Basic",
"import Mathlib.RingTheory.MvPolynomial.Basic",
"import ToMathlib.General"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "BitVec.ofFin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
... | [
{
"name": "Fin.succRecOnSameFinType",
"content": "@[elab_as_elim] def Fin.succRecOnSameFinType {motive : Fin r → Sort _}\n (zero : motive (0 : Fin r))\n (succ : ∀ i : Fin r, i + 1 < r → motive i → motive (i + 1)) : ∀ (i : Fin r), motive i\n | ⟨0, _⟩ => by admit /- proof elided -/\n | ⟨Nat.succ i_val... | [
{
"name": "List.length_ofFn",
"module": "Init.Data.List.OfFn"
},
{
"name": "List.getElem_ofFn",
"module": "Init.Data.List.OfFn"
},
{
"name": "List.get_eq_getElem",
"module": "Init.Data.List.Lemmas"
},
{
"name": "Fin.is_lt",
"module": "Init.Data.Fin.Lemmas"
},
{
"n... | [
{
"name": "testBit_true_eq_getBit_eq_1",
"content": "lemma testBit_true_eq_getBit_eq_1 (k n : Nat) : n.testBit k = ((Nat.getBit k n) = 1)"
},
{
"name": "testBit_false_eq_getBit_eq_0",
"content": "lemma testBit_false_eq_getBit_eq_0 (k n : Nat) :\n (n.testBit k = false) = ((Nat.getBit k n) = 0)"
... | [
{
"name": "MlPoly",
"content": "@[reducible]\ndef MlPoly (R : Type*) (n : ℕ) := Vector R (2 ^ n)"
},
{
"name": "MlPoly.monoToLagrangeLevel",
"content": "@[inline] def monoToLagrangeLevel {n : ℕ} (j : Fin n) : Vector R (2 ^ n) → Vector R (2 ^ n) :=\n fun v =>\n let stride : ℕ := 2 ^ j.val ... | [
{
"name": "MlPoly.forwardRange_length",
"content": "lemma forwardRange_length (n : ℕ) (r : Fin n) (l : Fin (r.val + 1)) :\n (forwardRange n r l).length = r.val - l.val + 1"
},
{
"name": "MlPoly.forwardRange_eq_of_r_eq",
"content": "lemma forwardRange_eq_of_r_eq (n : ℕ) (r1 r2 : Fin n) (h_r_eq... | import ArkLib.Data.Nat.Bitwise
import Mathlib.RingTheory.MvPolynomial.Basic
import ToMathlib.General
import ArkLib.Data.Fin.BigOperators
import ArkLib.Data.List.Lemmas
import ArkLib.Data.Vector.Basic
@[reducible]
def MlPoly (R : Type*) (n : ℕ) := Vector R (2 ^ n)
variable {R : Type*} {n : ℕ}
namespace MlPoly
section MlPolyInstances
end MlPolyInstances
section MlPolyMonomialBasisAndEvaluations
variable [CommRing R]
variable {S : Type*} [CommRing S]
variable {S : Type*} [CommRing S]
end MlPolyMonomialBasisAndEvaluations
end MlPoly
namespace MlPolyEval
section MlPolyEvalInstances
end MlPolyEvalInstances
section MlPolyLagrangeBasisAndEvaluations
variable [CommRing R]
variable {S : Type*} [CommRing S]
variable {S : Type*} [CommRing S]
end MlPolyLagrangeBasisAndEvaluations
end MlPolyEval
namespace MlPoly
variable {R : Type*} [AddCommGroup R]
@[inline] def monoToLagrangeLevel {n : ℕ} (j : Fin n) : Vector R (2 ^ n) → Vector R (2 ^ n) :=
fun v =>
let stride : ℕ := 2 ^ j.val
Vector.ofFn (fun i : Fin (2 ^ n) =>
if (BitVec.ofFin i).getLsb j then
v[i] + v[i - stride]'(Nat.sub_lt_of_lt i.isLt)
else
v[i])
@[inline] def lagrangeToMonoLevel {n : ℕ} (j : Fin n) : Vector R (2 ^ n) → Vector R (2 ^ n) :=
fun v =>
let stride : ℕ := 2 ^ j.val
Vector.ofFn (fun i : Fin (2 ^ n) =>
if (BitVec.ofFin i).getLsb j then
v[i] - v[i - stride]'(Nat.sub_lt_of_lt i.isLt)
else
v[i])
def forwardRange (n : ℕ) (r : Fin (n)) (l : Fin (r.val + 1)) : List (Fin n) :=
let len := r.val - l.val + 1
List.ofFn (fun (k : Fin len) =>
let val := l.val + k.val
have h_bound : val < n := by admit /- proof elided -/
)
def monoToLagrange_segment (n : ℕ) (r : Fin n) (l : Fin (r.val + 1)) :
Vector R (2 ^ n) → Vector R (2 ^ n) :=
let range := forwardRange n r l
(range.foldl (fun acc h => monoToLagrangeLevel h acc))
def lagrangeToMono_segment (n : ℕ) (r : Fin n) (l : Fin (r.val + 1)) :
Vector R (2 ^ n) → Vector R (2 ^ n) :=
let range := forwardRange n r l
(range.foldr (fun h acc => lagrangeToMonoLevel h acc)) | theorem mobius_apply_zeta_apply_eq_id (n : ℕ) [NeZero n] (r : Fin n) (l : Fin (r.val + 1))
(v : Vector R (2 ^ n)) : lagrangeToMono_segment n r l (monoToLagrange_segment n r l v) = v := | := by
induction r using Fin.succRecOnSameFinType with
| zero =>
rw [lagrangeToMono_segment, monoToLagrange_segment, forwardRange]
simp only [Fin.coe_ofNat_eq_mod, Nat.zero_mod, Fin.val_eq_zero, tsub_self, zero_add,
List.ofFn_succ, Fin.isValue, Fin.cast_zero, Nat.mod_succ, add_zero, Fin.mk_zero',
Fin.cast_succ_eq, Fin.val_succ, Fin.coe_cast, List.ofFn_zero, List.foldl_cons, List.foldl_nil,
List.foldr_cons, List.foldr_nil]
exact lagrangeToMonoLevel_monoToLagrangeLevel_id v 0
| succ r1 r1_lt_n h_r1 =>
unfold lagrangeToMono_segment monoToLagrange_segment
if h_l_eq_r: l.val = (r1 + 1).val then
rw [forwardRange]
simp only [List.ofFn_succ, Fin.coe_ofNat_eq_mod, Nat.zero_mod, add_zero, Fin.val_succ,
List.foldl_cons, List.foldr_cons]
simp_rw [h_l_eq_r]
simp only [Fin.eta, tsub_self, List.ofFn_zero, List.foldl_nil, List.foldr_nil]
exact lagrangeToMonoLevel_monoToLagrangeLevel_id v (r1 + 1)
else
have h_l_lt_r: l.val < (r1 + 1).val := by omega
have h_r1_add_1_val: (r1 + 1).val = r1.val + 1 := by
rw [Fin.val_add_one']; omega
have h_range_ne_empty: forwardRange n (r1 + 1) l ≠ [] := by
have h:= forwardRange_succ_right_ne_empty n
(r:=⟨r1, by omega⟩) (l:=⟨l, by simp only; omega⟩)
simp only [ne_eq] at h
have h_r1_add_1: r1 + 1 = ⟨r1.val + 1, by omega⟩ := by
exact Fin.eq_mk_iff_val_eq.mpr h_r1_add_1_val
rw [forwardRange_eq_of_r_eq (r1:=r1 + 1) (r2:=⟨r1.val + 1, by omega⟩) (h_r_eq:=h_r1_add_1)]
exact h
rw [List.foldr_split_inner (h:=h_range_ne_empty)]
rw [List.foldl_split_outer (h:=h_range_ne_empty)]
rw [lagrangeToMonoLevel_monoToLagrangeLevel_id]
have h_inductive := h_r1 (l := ⟨l, by exact Nat.lt_of_lt_of_eq h_l_lt_r h_r1_add_1_val⟩)
rw [lagrangeToMono_segment, monoToLagrange_segment] at h_inductive
simp only at h_inductive
have h_range_droplast: (forwardRange n (r1 + 1) l).dropLast
= forwardRange n r1 ⟨↑l, by omega⟩ := by
have h := forwardRange_dropLast n (r:=⟨r1, by omega⟩) (l:=⟨l, by simp only; omega⟩)
simp only [Fin.eta] at h
convert h
convert h_inductive | 7 | 84 | false | Applied verif. |
14 | Nat.getLowBits_succ | lemma getLowBits_succ {n: ℕ} (numLowBits: ℕ) :
getLowBits (numLowBits + 1) n = getLowBits numLowBits n
+ (getBit numLowBits n) <<< numLowBits | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "Nat.testBit",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "Nat.and_distrib_right",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Bool",
"modu... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.and_one_is_mod",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.eq_of_testBit_eq",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.mod_two_bne_zero",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "Nat.one_and_eq_mod_two",
"module": "I... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "Nat.getLowBits",
"content": "def getLowBits (numLowBits : ℕ) (n : ℕ) := n &&& ((1 <<< numLowBits) - 1)"
}
] | [
{
"name": "Nat.getBit_lt_2",
"content": "lemma getBit_lt_2 {k n : Nat} : getBit k n < 2"
},
{
"name": "Nat.eq_iff_eq_all_getBits",
"content": "lemma eq_iff_eq_all_getBits {n m : ℕ} : n = m ↔ ∀ k, getBit k n = getBit k m"
},
{
"name": "Nat.shiftRight_and_one_distrib",
"content": "lemm... | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1
def getLowBits (numLowBits : ℕ) (n : ℕ) := n &&& ((1 <<< numLowBits) - 1) | lemma getLowBits_succ {n: ℕ} (numLowBits: ℕ) :
getLowBits (numLowBits + 1) n = getLowBits numLowBits n
+ (getBit numLowBits n) <<< numLowBits := | := by
apply eq_iff_eq_all_getBits.mpr;
intro k
have h_getBit_lt_numLowBits: getBit numLowBits n < 2 := by exact getBit_lt_2
interval_cases h_getBit: getBit numLowBits n
· rw [Nat.zero_shiftLeft]
simp only [add_zero]
-- ⊢ getLowBits n (numLowBits + 1) >>> k &&& 1 = getLowBits n numLowBits >>> k &&& 1
change getBit k (getLowBits (numLowBits + 1) n) = getBit k (getLowBits numLowBits n)
have getBit_right := getBit_of_lowBits (n := n) (numLowBits := numLowBits) k
have getBit_left := getBit_of_lowBits (n := n) (numLowBits := numLowBits + 1) k
rw [getBit_right, getBit_left]
if h_k: k < numLowBits then
simp only [h_k, ↓reduceIte]
have h_k_lt: k < numLowBits + 1 := by omega
simp only [h_k_lt, ↓reduceIte]
else if h_k_eq: k = numLowBits then
simp only [h_k_eq]
simp only [lt_add_iff_pos_right, zero_lt_one, ↓reduceIte, lt_self_iff_false]
omega
else
have k_ne_lt: ¬(k < numLowBits) := by omega
have k_ne_lt_add_1: ¬(k < numLowBits + 1) := by omega
simp only [k_ne_lt_add_1, ↓reduceIte, k_ne_lt]
· change getBit k (getLowBits (numLowBits + 1) n)
= getBit k (getLowBits numLowBits n + 1 <<< numLowBits)
have getBit_left := getBit_of_lowBits (n := n) (numLowBits := numLowBits + 1) k
have getBit_right := getBit_of_lowBits (n := n) (numLowBits := numLowBits) k
rw [getBit_left]
have h_and_eq_0 := and_two_pow_eq_zero_of_getBit_0 (n:=getLowBits numLowBits n)
(i:=numLowBits) (by
simp only [getBit_of_lowBits (n := n) (numLowBits := numLowBits) numLowBits,
lt_self_iff_false, ↓reduceIte]
)
rw [←one_mul (a:=2 ^ numLowBits)] at h_and_eq_0
rw [←Nat.shiftLeft_eq (a:=1) (b:=numLowBits)] at h_and_eq_0
have h_sum_eq_xor := sum_of_and_eq_zero_is_xor (n:=getLowBits numLowBits n)
(m:=1 <<< numLowBits) (h_n_AND_m:=h_and_eq_0)
have h_sum_eq_or := xor_of_and_eq_zero_is_or (n:=getLowBits numLowBits n)
(m:=1 <<< numLowBits) (h_n_AND_m:=h_and_eq_0)
rw [h_sum_eq_or] at h_sum_eq_xor
rw [h_sum_eq_xor]
rw [getBit_of_or]
rw [getBit_of_lowBits]
conv_rhs =>
enter [2, 2]; rw [Nat.shiftLeft_eq, one_mul]
rw [getBit_two_pow]
if h_k: k < numLowBits then
have h_k_lt: k < numLowBits + 1 := by omega
simp only [h_k_lt, ↓reduceIte, h_k, beq_iff_eq]
have h_k_ne_eq: numLowBits ≠ k := by omega
simp only [h_k_ne_eq, ↓reduceIte, Nat.or_zero]
else if h_k_eq: k = numLowBits then
simp only [h_k_eq, lt_add_iff_pos_right, zero_lt_one, ↓reduceIte, lt_self_iff_false, BEq.rfl,
Nat.zero_or]
omega
else
have k_ne_lt: ¬(k < numLowBits) := by omega
have k_ne_lt_add_1: ¬(k < numLowBits + 1) := by omega
simp only [k_ne_lt_add_1, ↓reduceIte, k_ne_lt, beq_iff_eq, Nat.zero_or, right_eq_ite_iff,
zero_ne_one, imp_false, ne_eq]
omega | 4 | 103 | true | Applied verif. |
15 | rsum_eq_t1_square_aux | theorem rsum_eq_t1_square_aux
{curBTField : Type*} [Field curBTField] -- curBTField ≃ 𝔽_{2^{2^k}}
(u : curBTField) -- here u is already lifted to curBTField
(k : ℕ)
(x_pow_card : ∀ (x : curBTField), x ^ (2 ^ (2 ^ (k))) = x)
(u_ne_zero : u ≠ 0)
(trace_map_prop : TraceMapProperty curBTField u k):
∑ j ∈ Finset.Icc 1 (2 ^ (k)), u ^ (2 ^ 2 ^ (k) - 2 ^ j) = u | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Prelude.lean | [
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.FieldTheory.Finite.GaloisField",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.StdBasis"
] | [
{
"name": "Field",
"module": "Mathlib.Algebra.Field.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.range",
"module": "Mathlib.Data.Finset.Range"
},
{
"name": "False.elim",
"module": "Init.Prelude"
},
{
"name": "Finset.Icc",
... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.pow_le_pow_right",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.pow_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.zero_le",
"module": "Init.Prelude"
},
{
"name": "Finset.mem_Icc",
"module": "Mathlib.Order.Interval.Finset.Defs"
},
{
"... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "TraceMapProperty",
"content": "structure TraceMapProperty (F : Type*) [Field F] (u : F) (k : ℕ) : Prop where\n element_trace : ∑ i ∈ Finset.range (2 ^ k), u ^ (2 ^ i) = 1\n inverse_trace : ∑ i ∈ Finset.range (2 ^ k), (u⁻¹) ^ (2 ^ i) = 1"
}
] | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
}
] | import Mathlib.FieldTheory.Finite.GaloisField
import ArkLib.Data.Fin.BigOperators
import ArkLib.Data.Nat.Bitwise
import Mathlib.LinearAlgebra.StdBasis
noncomputable section Preliminaries
open Polynomial
open AdjoinRoot
open Module
notation : 10 "GF(" term : 10 ")" => GaloisField term 1
structure TraceMapProperty (F : Type*) [Field F] (u : F) (k : ℕ) : Prop where
element_trace : ∑ i ∈ Finset.range (2 ^ k), u ^ (2 ^ i) = 1
inverse_trace : ∑ i ∈ Finset.range (2 ^ k), (u⁻¹) ^ (2 ^ i) = 1 | theorem rsum_eq_t1_square_aux
{curBTField : Type*} [Field curBTField] -- curBTField ≃ 𝔽_{2^{2^k}}
(u : curBTField) -- here u is already lifted to curBTField
(k : ℕ)
(x_pow_card : ∀ (x : curBTField), x ^ (2 ^ (2 ^ (k))) = x)
(u_ne_zero : u ≠ 0)
(trace_map_prop : TraceMapProperty curBTField u k):
∑ j ∈ Finset.Icc 1 (2 ^ (k)), u ^ (2 ^ 2 ^ (k) - 2 ^ j) = u := | := by
have trace_map_icc_t1 : ∑ j ∈ Finset.Icc 0 (2^(k)-1), u ^ (2^j) = 1 := by
rw [←Nat.range_succ_eq_Icc_zero (2^(k)-1), Nat.sub_add_cancel (h:=one_le_two_pow_n (k))]
exact trace_map_prop.1
have trace_map_icc_t1_inv : ∑ j ∈ Finset.Icc 0 (2^(k)-1), u⁻¹ ^ (2^j) = 1 := by
rw [←Nat.range_succ_eq_Icc_zero (2^(k)-1), Nat.sub_add_cancel (h:=one_le_two_pow_n (k))]
exact trace_map_prop.2
calc
∑ j ∈ Finset.Icc 1 (2 ^ (k)), u ^ (2 ^ 2 ^ (k) - 2 ^ j)
= ∑ j ∈ Finset.Icc 1 (2 ^ (k)), (u ^ (2 ^ 2 ^ (k)) * ((u) ^ 2 ^ j)⁻¹) := by
apply Finset.sum_congr rfl (fun j hj => by
simp [Finset.mem_Icc] at hj -- hj : 1 ≤ j ∧ j ≤ 2 ^ (k)
have h_gte_0_pow : 2 ^ j ≤ 2 ^ 2 ^ (k) := by
apply pow_le_pow_right₀ (by decide) (hj.2)
rw [pow_sub₀ (a := u) (ha := u_ne_zero) (h := h_gte_0_pow)]
)
_ = ∑ j ∈ Finset.Icc 1 (2 ^ (k)), ((u) * ((u) ^ 2 ^ j)⁻¹) := by
rw [x_pow_card (u)]
_ = u * ∑ j ∈ Finset.Icc 1 (2 ^ (k)), ((u) ^ 2 ^ j)⁻¹ := by rw [Finset.mul_sum]
_ = u * ∑ j ∈ Finset.Icc 1 (2 ^ (k)), (((u)⁻¹) ^ 2 ^ j) := by
congr
ext j
rw [←inv_pow (a := u) (n := 2 ^ j)]
_ = u * ∑ j ∈ Finset.Icc 0 (2 ^ (k) - 1), ((u⁻¹) ^ 2 ^ j) := by
rw [mul_right_inj' (a := u) (ha := u_ne_zero)]
apply Finset.sum_bij' (fun i _ => if i = 2^(k) then 0 else i)
(fun i _ => if i = 0 then 2^(k) else i)
-- hi : Maps to Icc 0 (2^(k))
· intro i hi
simp [Finset.mem_Icc] at hi ⊢
by_cases h : i = 2^(k)
· simp [h];
· simp [h] -- ⊢ i = 0 → 2 ^ (k) = i
intro i_eq
have this_is_false : False := by
have h1 := hi.left -- h1 : 1 ≤ i
rw [i_eq] at h1 -- h1 : 1 ≤ 0
have ne_one_le_zero : ¬(1 ≤ 0) := Nat.not_le_of_gt (by decide)
exact ne_one_le_zero h1
exact False.elim this_is_false
-- hj : Maps back
· intro i hi
simp [Finset.mem_Icc] at hi -- hi : i ≤ 2 ^ (k) - 1
by_cases h : i = 0
· simp [h];
· simp [h];
intro i_eq
have this_is_false : False := by
rw [i_eq] at hi
conv at hi =>
lhs
rw [←add_zero (a:=2^(k))]
-- conv at hi =>
-- rhs
have zero_lt_2_pow_k_plus_1 : 0 < 2^(k) := by
norm_num
have h_contra : ¬(2^(k) ≤ 2^(k) - 1) := by
apply Nat.not_le_of_gt
exact Nat.sub_lt zero_lt_2_pow_k_plus_1 (by norm_num)
exact h_contra hi
exact False.elim this_is_false
-- hij : j (i a) = a
· intro i hi -- hi : 1 ≤ i ∧ i ≤ 2 ^ (k)
simp [Finset.mem_Icc] at hi
by_cases h : i = 2^(k)
· simp [h]; exact x_pow_card u
· simp [h]
-- hji : i (j b) = b
· intro i hi
simp [Finset.mem_Icc] at hi
by_cases h : i = 0
· simp [h]
· simp only [Finset.mem_Icc, zero_le, true_and]; -- hi : 1 ≤ i ∧ i ≤ 2 ^ (k)
-- h : ¬i = 0
-- ⊢ (if i = 2 ^ (k) then 0 else i) ≤ 2 ^ (k) - 1
split_ifs with h2
· -- Case : i = 2 ^ (k)
-- Goal : 0 ≤ 2 ^ (k) - 1
exact Nat.zero_le _
· -- Case : i ≠ 2 ^ (k)
-- Goal : i ≤ 2 ^ (k) - 1
have : i < 2 ^ (k) := by
apply lt_of_le_of_ne hi.right h2
exact Nat.le_pred_of_lt this
-- h_sum : Values match
· intro i hi
simp [Finset.mem_Icc] at hi
rw [Finset.mem_Icc]
split_ifs with h2
· -- hi : i ≤ 2 ^ (k) - 1, h2 : i = 0
-- ⊢ 1 ≤ 2 ^ (k) ∧ 2 ^ (k) ≤ 2 ^ (k)
exact ⟨one_le_two_pow_n (k), le_refl _⟩
· -- Case : hi : i ≤ 2 ^ (k) - 1, h2 : ¬i = 0
-- ⊢ 1 ≤ i ∧ i ≤ 2 ^ (k)
have one_le_i : 1 ≤ i := by
apply Nat.succ_le_of_lt
exact Nat.pos_of_ne_zero h2
have tmp : i ≤ 2^(k):= by
calc i ≤ (2^(k)-1).succ := Nat.le_succ_of_le hi
_ = 2^(k) := by rw [Nat.succ_eq_add_one, Nat.sub_add_cancel
(h:=one_le_two_pow_n (k))]
exact ⟨one_le_i, tmp⟩
_ = u := by rw [trace_map_icc_t1_inv, mul_one] | 2 | 35 | true | Applied verif. |
16 | AdditiveNTT.rootMultiplicity_prod_W_comp_X_sub_C | omit h_Fq_char_prime hF₂ in
lemma rootMultiplicity_prod_W_comp_X_sub_C
(i : Fin r) (h_i_add_1 : i + 1 < r) (a : L) :
rootMultiplicity a ((univ : Finset 𝔽q).prod (fun c => (W 𝔽q β i).comp (X - C (c • β i)))) =
if a ∈ (U 𝔽q β (i+1) : Set L) then 1 else 0 | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Finset.prod_eq_zero_iff",
"module": "Mathlib.Algebra.BigOperators.GroupWithZero.Finset"
},
{
"name": "Nat.not_lt_zero",
"module": "Init.Prelude"
},
{
"name": "Polynomial.X_sub_C_ne_zero",
"module": "Mathlib.Algebra.Polynomial.Degree.Operations"
},
{
"name": "Set.Ic... | [
{
"name": "Fin.lt_succ'",
"content": "lemma Fin.lt_succ' (a : Fin r) (h_a_add_1 : a + 1 < r) : a < a + 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
},
{
"name": "Fin.le_succ",
"content": "lemma F... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.algEquivAevalXSubC",
... | [
{
"name": "AdditiveNTT.βᵢ_not_in_Uᵢ",
"content": "lemma βᵢ_not_in_Uᵢ (i : Fin r) :\n β i ∉ U 𝔽q β i"
},
{
"name": "AdditiveNTT.root_U_lift_down",
"content": "omit [Fintype L] [DecidableEq L] [Fintype 𝔽q] h_Fq_char_prime in\ntheorem root_U_lift_down\n (i : Fin r) (h_i_add_1 : i + 1 < r) (a ... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
@[simps!]
noncomputable def algEquivAevalXSubC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := | omit h_Fq_char_prime hF₂ in
lemma rootMultiplicity_prod_W_comp_X_sub_C
(i : Fin r) (h_i_add_1 : i + 1 < r) (a : L) :
rootMultiplicity a ((univ : Finset 𝔽q).prod (fun c => (W 𝔽q β i).comp (X - C (c • β i)))) =
if a ∈ (U 𝔽q β (i+1) : Set L) then 1 else 0 := | := by
rw [←Polynomial.count_roots]
set f := fun c: 𝔽q => (W 𝔽q β i).comp (X - C (c • β i)) with hf
-- ⊢ Multiset.count a (univ.prod f).roots = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_prod_ne_zero: univ.prod f ≠ 0 := Prod_W_comp_X_sub_C_ne_zero 𝔽q β i
rw [roots_prod (f := f) (s := univ (α := 𝔽q)) h_prod_ne_zero]
set roots_f := fun c: 𝔽q => (f c).roots with hroots_f
rw [Multiset.count_bind]
-- ⊢ (Multiset.map (fun b ↦ Multiset.count a (roots_f b)) univ.val).sum
-- = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_roots_f_eq_roots_W : ∀ b : 𝔽q,
roots_f b = (W 𝔽q β i).roots.map (fun r => r + (b • β i)) := by
intro b
rw [hroots_f, hf]
exact roots_comp_X_sub_C (p := (W 𝔽q β i)) (a := (b • β i))
simp_rw [h_roots_f_eq_roots_W]
set shift_up := fun x: 𝔽q => fun r: L => r + x • β i with hshift_up
have h_shift_up_all: ∀ x: 𝔽q, ∀ r: L, shift_up x r = r + x • β i := by
intro x r
rw [hshift_up]
simp only [sum_map_val, SetLike.mem_coe]
have h_a: ∀ x: 𝔽q, a = shift_up x (a - x • β i) := by
intro x
rw [hshift_up]
simp_all only [ne_eq, implies_true, sub_add_cancel, f, roots_f, shift_up]
conv_lhs =>
enter [2, x] -- focus on the inner Multiset.count
rw [h_a x]
enter [2]
enter [1]
enter [r]
rw [←h_shift_up_all x r] -- rewrite to another notation
-- ⊢ ∑ x, Multiset.count (shift_up x (a - x • β i)) (Multiset.map (shift_up x) (W 𝔽q β i).roots)
-- = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_shift_up_inj: ∀ x: 𝔽q, Function.Injective (shift_up x) := by
intro x
unfold shift_up
exact add_left_injective (x • β i)
have h_count_map: ∀ x: 𝔽q,
Multiset.count (shift_up x (a - x • β i)) (Multiset.map (shift_up x) (W 𝔽q β i).roots) =
Multiset.count (a - x • β i) (W 𝔽q β i).roots := by
-- transform to counting (a - x • β i) in the roots of Wᵢ
intro x
have h_shift_up_inj_x: Function.Injective (shift_up x) := h_shift_up_inj x
simp only [Multiset.count_map_eq_count' (hf := h_shift_up_inj_x), count_roots]
conv_lhs =>
enter [2, x]
rw [h_count_map x]
-- ⊢ ∑ x, Multiset.count (a - x • β i) (W 𝔽q β i).roots
-- = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_root_lift_down := root_U_lift_down 𝔽q β i h_i_add_1 a
have h_root_lift_up := root_U_lift_up 𝔽q β i h_i_add_1 a
conv_lhs =>
enter [2, x]
simp only [count_roots]
rw [rootMultiplicity_W]
by_cases h_a_mem_U_i : a ∈ ↑(U 𝔽q β (i + 1))
· -- ⊢ (∑ x, if a - x • β i ∈ ↑(U 𝔽q β i) then 1 else 0)
-- = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_true: (a ∈ ↑(U 𝔽q β (i + 1))) = True := by simp only [h_a_mem_U_i]
rcases h_root_lift_down h_a_mem_U_i with ⟨x0, hx0, hx0_unique⟩
conv =>
rhs
-- | if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0 => reduce this to 1
enter [1]
exact h_true -- maybe there can be a better way to do this
rw [ite_true]
classical
-- ⊢ (∑ x, if a - x • β i ∈ ↑(U 𝔽q β i) then 1 else 0) = 1
have h_true: ∀ x: 𝔽q,
if x = x0 then a - x • β i ∈ ↑(U 𝔽q β i) else a - x • β i ∉ ↑(U 𝔽q β i) := by
intro x
by_cases h_x_eq_x0 : x = x0
· rw [if_pos h_x_eq_x0] -- ⊢ a - x • β i ∈ U 𝔽q β i
rw [←h_x_eq_x0] at hx0
exact hx0
· rw [if_neg h_x_eq_x0] -- ⊢ a - x • β i ∉ U 𝔽q β i
by_contra h_mem
have h1 := hx0_unique x
simp only [h_mem, forall_const] at h1
contradiction
have h_true_x: ∀ x: 𝔽q, (a - x • β i ∈ ↑(U 𝔽q β i)) = if x = x0 then True else False := by
intro x
by_cases h_x_eq_x0 : x = x0
· rw [if_pos h_x_eq_x0]
rw [←h_x_eq_x0] at hx0
simp only [hx0]
· rw [if_neg h_x_eq_x0]
by_contra h_mem
push_neg at h_mem
simp only [ne_eq, eq_iff_iff, iff_false, not_not] at h_mem
have h2 := hx0_unique x
simp only [h_mem, forall_const] at h2
contradiction
conv =>
lhs
enter [2, x]
simp only [SetLike.mem_coe, h_true_x x, if_false_right, and_true]
rw [sum_ite_eq']
simp only [mem_univ, ↓reduceIte]
· -- ⊢ (∑ x, if a - x • β i ∈ ↑(U 𝔽q β i) then 1 else 0)
-- = if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0
have h_false: (a ∈ ↑(U 𝔽q β (i + 1))) = False := by simp only [h_a_mem_U_i]
conv =>
rhs -- | if a ∈ ↑(U 𝔽q β (i + 1)) then 1 else 0 => reduce this to 1
enter [1]
exact h_false -- maybe there can be a better way to do this
rw [ite_false]
have h_zero_x: ∀ x: 𝔽q, (a - x • β i ∈ ↑(U 𝔽q β i)) = False := by
intro x
by_contra h_mem
simp only [eq_iff_iff, iff_false, not_not] at h_mem -- h_mem : a - x • β i ∈ U 𝔽q β i
have h_a_mem_U_i := h_root_lift_up x h_mem
contradiction
conv =>
lhs
enter [2, x]
simp only [SetLike.mem_coe, h_zero_x x, if_false_right, and_true]
simp only [↓reduceIte, sum_const_zero] | 4 | 157 | false | Applied verif. |
17 | Binius.BinaryBasefold.is_fiber_iff_generates_quotient_point | theorem is_fiber_iff_generates_quotient_point (i : Fin ℓ) (steps : ℕ)
(h_i_add_steps : i.val + steps ≤ ℓ)
(x : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩))
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by omega⟩)) :
let qMapFiber := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by simp only; exact fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) (y := y)
let k := pointToIterateQuotientIndex (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := h_i_add_steps) (x := x)
y = iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i (k := steps) (h_bound := h_i_add_steps) x ↔
qMapFiber k = x | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Prelude.lean | [
"import ArkLib.Data.MvPolynomial.Multilinear",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.CodingTheory.ReedSolomon",
"import ArkLib.Data.Vector.Basic",
"import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound",
"import ArkLib.Data.FieldThe... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\... | [
{
"name": "Fin.eta",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "add_zero",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Module.Basis.repr_linearCombination",
"module": "Mathlib.LinearAlgebra.Basis.Defs"
},
{
"name": "Module.Basis.repr_symm_apply",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "lt_add_of_pos_right_of_le",
"content": "@[simp]\nlemma lt_add_of_pos_right_of_le (a b c : ℕ) [NeZero c] (h : a ≤ b) : a < b + c"
},
{
... | [
{
"name": "Binius.BinaryBasefold.fiber_coeff",
"content": "noncomputable def fiber_coeff\n (i : Fin r) (steps : ℕ)\n (j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))\n (y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=\n if hj : j.val < steps then\n if Nat.getBit (k := j) (n := elemen... | [
{
"name": "Binius.BinaryBasefold.fin_ℓ_steps_lt_ℓ_add_R",
"content": "omit [NeZero ℓ] in\nlemma fin_ℓ_steps_lt_ℓ_add_R (i : Fin ℓ) (steps : ℕ) (h : i.val + steps ≤ ℓ)\n : i.val + steps < ℓ + 𝓡"
},
{
"name": "Binius.BinaryBasefold.qMap_total_fiber_repr_coeff",
"content": "lemma qMap_total_fib... | import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch
import ArkLib.Data.CodingTheory.ReedSolomon
import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.MvPolynomial.Multilinear
import ArkLib.Data.Vector.Basic
import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
section Preliminaries
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
end Preliminaries
noncomputable section -- expands with 𝔽q in front
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L] [CharP L 2]
variable (𝔽q : Type) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ 𝓡 ϑ : ℕ} (γ_repetitions : ℕ) [NeZero ℓ] [NeZero 𝓡] [NeZero ϑ] -- Should we allow ℓ = 0?
variable {h_ℓ_add_R_rate : ℓ + 𝓡 < r} -- ℓ ∈ {1, ..., r-1}
variable {𝓑 : Fin 2 ↪ L}
section Essentials
noncomputable def fiber_coeff
(i : Fin r) (steps : ℕ)
(j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))
(y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=
if hj : j.val < steps then
if Nat.getBit (k := j) (n := elementIdx) = 0 then 0 else 1
else y_coeffs ⟨j.val - steps, by admit /- proof elided -/
⟩
noncomputable def qMap_total_fiber
(i : Fin r) (steps : ℕ) (h_i_add_steps : i.val + steps < ℓ + 𝓡)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by admit /- proof elided -/
⟩)) :
Fin (2 ^ steps) → sDomain 𝔽q β h_ℓ_add_R_rate i :=
if h_steps : steps = 0 then by
subst h_steps
simp only [add_zero, Fin.eta] at y
exact fun _ => y
else by
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate (i := ⟨i+steps,by admit /- proof elided -/
⟩) (by admit /- proof elided -/
)
let y_coeffs : Fin (ℓ + 𝓡 - (↑i + steps)) →₀ 𝔽q := basis_y.repr y
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ (by admit /- proof elided -/
)
exact fun elementIdx => by admit /- proof elided -/
def pointToIterateQuotientIndex (i : Fin (ℓ + 1)) (steps : ℕ) (h_i_add_steps : i.val + steps ≤ ℓ)
(x : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩)) : Fin (2 ^ steps) := | theorem is_fiber_iff_generates_quotient_point (i : Fin ℓ) (steps : ℕ)
(h_i_add_steps : i.val + steps ≤ ℓ)
(x : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩))
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by omega⟩)) :
let qMapFiber := | := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by simp only; exact fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) (y := y)
let k := pointToIterateQuotientIndex (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := h_i_add_steps) (x := x)
y = iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i (k := steps) (h_bound := h_i_add_steps) x ↔
qMapFiber k = x := by
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩
(by simp only; omega)
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i.val + steps, by omega⟩
(h_i := by apply Nat.lt_add_of_pos_right_of_le; omega)
simp only
set k := pointToIterateQuotientIndex (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := h_i_add_steps) (x := x)
constructor
· intro h_x_generates_y
-- ⊢ qMap_total_fiber ...` ⟨↑i, ⋯⟩ steps ⋯ y k = x
-- We prove that `qMap_total_fiber` with this `k` reconstructs `x` via basis repr
apply basis_x.repr.injective
ext j
let reConstructedX := basis_x.repr (qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩)
(steps := steps) (h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y) k)
have h_repr_of_reConstructedX := qMap_total_fiber_repr_coeff 𝔽q β i (steps := steps)
(h_i_add_steps := by omega) (y := y) (k := k) (j := j)
simp only at h_repr_of_reConstructedX
-- ⊢ repr of reConstructedX at j = repr of x at j
rw [h_repr_of_reConstructedX]; dsimp [k, pointToIterateQuotientIndex, fiber_coeff];
rw [getBit_of_binaryFinMapToNat]; simp only [Fin.eta, dite_eq_right_iff, ite_eq_left_iff,
one_ne_zero, imp_false, Decidable.not_not]
-- Now we only need to do case analysis
by_cases h_j : j.val < steps
· -- Case 1 : The first `steps` coefficients, determined by `k`.
simp only [h_j, ↓reduceDIte, forall_const]
by_cases h_coeff_j_of_x : basis_x.repr x j = 0
· simp only [basis_x, h_coeff_j_of_x, ↓reduceIte];
· simp only [basis_x, h_coeff_j_of_x, ↓reduceIte];
have h_coeff := 𝔽q_element_eq_zero_or_eq_one 𝔽q (c := basis_x.repr x j)
simp only [h_coeff_j_of_x, false_or] at h_coeff
exact id (Eq.symm h_coeff)
· -- Case 2 : The remaining coefficients, determined by `y`.
simp only [h_j, ↓reduceDIte]
simp only [basis_x]
-- ⊢ Here we compare coeffs, not the basis elements
simp only [h_x_generates_y]
have h_res := getSDomainBasisCoeff_of_iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i (k := steps)
(h_bound := by omega) x (j := ⟨j - steps, by -- TODO : make this index bound proof cleaner
simp only; rw [←Nat.sub_sub]; -- ⊢ ↑j - steps < ℓ + 𝓡 - ↑i - steps
apply Nat.sub_lt_sub_right;
· exact Nat.le_of_not_lt h_j
· exact j.isLt
⟩) -- ⊢ ↑j - steps < ℓ + 𝓡 - (↑i + steps)
have h_j_sub_add_steps : j - steps + steps = j := by omega
simp only at h_res
simp only [h_j_sub_add_steps, Fin.eta] at h_res
exact h_res
· intro h_x_is_fiber_of_y
-- y is the quotient point of x over steps steps
apply generates_quotient_point_if_is_fiber_of_y (h_i_add_steps := h_i_add_steps)
(x := x) (y := y) (hx_is_fiber := by use k; exact h_x_is_fiber_of_y.symm) | 6 | 127 | false | Applied verif. |
18 | ConcreteBinaryTower.Z_square_eq | lemma Z_square_eq (k : ℕ) (prevBTFieldProps : ConcreteBTFieldProps (k := k))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI : Field (ConcreteBTField (k + 1)) := mkFieldInstance curBTFieldProps
(Z (k + 1)) ^ 2 = 《 Z (k), 1 》 | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "Al... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dcast (Eq.refl n) bv = bv"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction | lemma Z_square_eq (k : ℕ) (prevBTFieldProps : ConcreteBTFieldProps (k := k))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI : Field (ConcreteBTField (k + 1)) := | := mkFieldInstance curBTFieldProps
(Z (k + 1)) ^ 2 = 《 Z (k), 1 》 := by
letI : Field (ConcreteBTField (k + 1)) := mkFieldInstance curBTFieldProps
have hmul : ∀ (a b : ConcreteBTField (k - 1)), concrete_mul a b = a * b := fun a b => rfl
rw [pow_two]
change concrete_mul (Z (k + 1)) (Z (k + 1)) = 《 Z (k), 1 》
have h_split_Z_k_add_1 : split (k:=k+1) (h:=by omega) (Z (k + 1)) = (1, 0) := by
exact Eq.symm
(split_of_join (by omega) (Z (k + 1)) 1 0 rfl)
have h_mul_eq := curBTFieldProps.mul_eq (a:=Z (k+1)) (b:=Z (k+1))
(a₁:=1) (a₀:=0) (b₁:=1) (b₀:=0) (h_k:=by omega)
(by exact id (Eq.symm h_split_Z_k_add_1)) (by exact id (Eq.symm h_split_Z_k_add_1))
rw [h_mul_eq]
simp_rw [←zero_is_0, ←one_is_1]
simp only [Nat.add_one_sub_one]
simp_rw [prevBTFieldProps.mul_zero, prevBTFieldProps.mul_one,
prevBTFieldProps.add_zero, prevBTFieldProps.one_mul]
simp_rw [prevBTFieldProps.zero_add] | 8 | 140 | false | Applied verif. |
19 | Binius.BinaryBasefold.qMap_total_fiber_disjoint | theorem qMap_total_fiber_disjoint
(i : Fin ℓ) (steps : ℕ) (h_i_add_steps : i + steps ≤ ℓ)
{y₁ y₂ : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i.val + steps, by omega⟩}
(hy_ne : y₁ ≠ y₂) :
Disjoint
((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) y₁ '' Set.univ).toFinset)
((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) y₂ '' Set.univ).toFinset) | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Prelude.lean | [
"import ArkLib.Data.MvPolynomial.Multilinear",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.CodingTheory.ReedSolomon",
"import ArkLib.Data.Vector.Basic",
"import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound",
"import ArkLib.Data.FieldThe... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\n AdditiveNTT.normalizedW_is_additive 𝔽q β i\n Submodule.map (polyEvalLinearMap W_i_norm h_... | [
{
"name": "Fin.eta",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "add_zero",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Module.Basis.repr_linearCombination",
"module": "Mathlib.LinearAlgebra.Basis.Defs"
},
{
"name": "Module.Basis.repr_symm_apply",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "lt_add_of_pos_right_of_le",
"content": "@[simp]\nlemma lt_add_of_pos_right_of_le (a b c : ℕ) [NeZero c] (h : a ≤ b) : a < b + c"
},
{
... | [
{
"name": "Binius.BinaryBasefold.fiber_coeff",
"content": "noncomputable def fiber_coeff\n (i : Fin r) (steps : ℕ)\n (j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))\n (y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=\n if hj : j.val < steps then\n if Nat.getBit (k := j) (n := elemen... | [
{
"name": "Binius.BinaryBasefold.fin_ℓ_steps_lt_ℓ_add_R",
"content": "omit [NeZero ℓ] in\nlemma fin_ℓ_steps_lt_ℓ_add_R (i : Fin ℓ) (steps : ℕ) (h : i.val + steps ≤ ℓ)\n : i.val + steps < ℓ + 𝓡"
},
{
"name": "Binius.BinaryBasefold.qMap_total_fiber_repr_coeff",
"content": "lemma qMap_total_fib... | import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch
import ArkLib.Data.CodingTheory.ReedSolomon
import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.MvPolynomial.Multilinear
import ArkLib.Data.Vector.Basic
import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
section Preliminaries
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
end Preliminaries
noncomputable section -- expands with 𝔽q in front
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L] [CharP L 2]
variable (𝔽q : Type) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ 𝓡 ϑ : ℕ} (γ_repetitions : ℕ) [NeZero ℓ] [NeZero 𝓡] [NeZero ϑ] -- Should we allow ℓ = 0?
variable {h_ℓ_add_R_rate : ℓ + 𝓡 < r} -- ℓ ∈ {1, ..., r-1}
variable {𝓑 : Fin 2 ↪ L}
section Essentials
noncomputable def fiber_coeff
(i : Fin r) (steps : ℕ)
(j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))
(y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=
if hj : j.val < steps then
if Nat.getBit (k := j) (n := elementIdx) = 0 then 0 else 1
else y_coeffs ⟨j.val - steps, by admit /- proof elided -/
⟩
noncomputable def qMap_total_fiber
(i : Fin r) (steps : ℕ) (h_i_add_steps : i.val + steps < ℓ + 𝓡)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by admit /- proof elided -/
⟩)) :
Fin (2 ^ steps) → sDomain 𝔽q β h_ℓ_add_R_rate i :=
if h_steps : steps = 0 then by
subst h_steps
simp only [add_zero, Fin.eta] at y
exact fun _ => y
else by
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate (i := ⟨i+steps,by admit /- proof elided -/
⟩) (by admit /- proof elided -/
)
let y_coeffs : Fin (ℓ + 𝓡 - (↑i + steps)) →₀ 𝔽q := basis_y.repr y
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ (by admit /- proof elided -/
)
exact fun elementIdx => by admit /- proof elided -/
def pointToIterateQuotientIndex (i : Fin (ℓ + 1)) (steps : ℕ) (h_i_add_steps : i.val + steps ≤ ℓ)
(x : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩)) : Fin (2 ^ steps) := | theorem qMap_total_fiber_disjoint
(i : Fin ℓ) (steps : ℕ) (h_i_add_steps : i + steps ≤ ℓ)
{y₁ y₂ : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i.val + steps, by omega⟩}
(hy_ne : y₁ ≠ y₂) :
Disjoint
((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) y₁ '' Set.univ).toFinset)
((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps) y₂ '' Set.univ).toFinset) := | := by
-- Proof by contradiction. Assume the intersection is non-empty.
rw [Finset.disjoint_iff_inter_eq_empty]
by_contra h_nonempty
-- Let `x` be an element in the intersection of the two fiber sets.
obtain ⟨x, h_x_mem_inter⟩ := Finset.nonempty_of_ne_empty h_nonempty
have hx₁ := Finset.mem_of_mem_inter_left h_x_mem_inter
have hx₂ := Finset.mem_of_mem_inter_right h_x_mem_inter
-- A helper lemma : applying the forward map to a point in a generated fiber returns
-- the original quotient point.
have iteratedQuotientMap_of_qMap_total_fiber_eq_self
(y : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i.val + steps, by omega⟩)
(k : Fin (2 ^ steps)) :
iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩) (k := steps)
(h_bound := by omega)
(qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y) k) = y := by
have h := generates_quotient_point_if_is_fiber_of_y
(h_i_add_steps := h_i_add_steps) (x:=
((qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y) k) :
sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩))
) (y := y) (hx_is_fiber := by use k)
exact h.symm
have h_exists_k₁ : ∃ k, x = qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) y₁ k := by
-- convert (x ∈ Finset of the image of the fiber) to statement
-- about membership in the Set.
rw [Set.mem_toFinset] at hx₁
rw [Set.mem_image] at hx₁ -- Set.mem_image gives us t an index that maps to x
-- ⊢ `∃ (k : Fin (2 ^ steps)), k ∈ Set.univ ∧ qMap_total_fiber ... y₁ k = x`.
rcases hx₁ with ⟨k, _, h_eq⟩
use k; exact h_eq.symm
have h_exists_k₂ : ∃ k, x = qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) y₂ k := by
rw [Set.mem_toFinset] at hx₂
rw [Set.mem_image] at hx₂ -- Set.mem_image gives us t an index that maps to x
rcases hx₂ with ⟨k, _, h_eq⟩
use k; exact h_eq.symm
have h_y₁_eq_quotient_x : y₁ =
iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i steps h_i_add_steps x := by
apply generates_quotient_point_if_is_fiber_of_y (hx_is_fiber := by exact h_exists_k₁)
have h_y₂_eq_quotient_x : y₂ =
iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate i steps h_i_add_steps x := by
apply generates_quotient_point_if_is_fiber_of_y (hx_is_fiber := by exact h_exists_k₂)
let kQuotientIndex := pointToIterateQuotientIndex (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by omega) (x := x)
-- Since `x` is in the fiber of `y₁`, applying the forward map to `x` yields `y₁`.
have h_map_x_eq_y₁ : iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩)
(k := steps) (h_bound := by omega) x = y₁ := by
have h := iteratedQuotientMap_of_qMap_total_fiber_eq_self (y := y₁) (k := kQuotientIndex)
have hx₁ : x = qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) y₁ kQuotientIndex := by
have h_res := is_fiber_iff_generates_quotient_point 𝔽q β i steps (by omega)
(x := x) (y := y₁).mp (h_y₁_eq_quotient_x)
exact h_res.symm
rw [hx₁]
exact iteratedQuotientMap_of_qMap_total_fiber_eq_self y₁ kQuotientIndex
-- Similarly, since `x` is in the fiber of `y₂`, applying the forward map yields `y₂`.
have h_map_x_eq_y₂ : iteratedQuotientMap 𝔽q β h_ℓ_add_R_rate (i := ⟨i, by omega⟩)
(k := steps) (h_bound := by omega) x = y₂ := by
-- have h := iteratedQuotientMap_of_qMap_total_fiber_eq_self (y := y₂) (k := kQuotientIndex)
have hx₂ : x = qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) y₂ kQuotientIndex := by
have h_res := is_fiber_iff_generates_quotient_point 𝔽q β i steps (by omega)
(x := x) (y := y₂).mp (h_y₂_eq_quotient_x)
exact h_res.symm
rw [hx₂]
exact iteratedQuotientMap_of_qMap_total_fiber_eq_self y₂ kQuotientIndex
exact hy_ne (h_map_x_eq_y₁.symm.trans h_map_x_eq_y₂) | 6 | 136 | false | Applied verif. |
20 | AdditiveNTT.even_index_intermediate_novel_basis_decomposition | lemma even_index_intermediate_novel_basis_decomposition (i : Fin ℓ) (j : Fin (2 ^ (ℓ - i - 1))) :
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ ⟨j * 2, by
apply mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
⟩ = (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le j (ℓ-i-1) (ℓ-(i+1)) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Polynomial.comp_assoc",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fin.foldl_succ",
"module": "Init.Data.Fin.Fol... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "getBit_zero_of_two_mul",
"content": "lemma getBit_zero_of_two_mul {n : ℕ} : getBit 0 (2*n) = 0"
},
{
"name": "lt_two_pow_of_lt_two_pow... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.intermedia... | [
{
"name": "AdditiveNTT.Polynomial.foldl_comp",
"content": "omit [Fintype L] [DecidableEq L] in\ntheorem Polynomial.foldl_comp (n : ℕ) (f : Fin n → L[X]) : ∀ initInner initOuter: L[X],\n Fin.foldl (n:=n) (fun acc j => (f j).comp acc) (initOuter.comp initInner)\n = (Fin.foldl (n:=n) (fun acc j => (f j).... | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X)
noncomputable def intermediateNovelBasisX (i : Fin (ℓ + 1)) (j : Fin (2 ^ (ℓ - i))) : L[X] :=
(Finset.univ: Finset (Fin (ℓ - i)) ).prod (fun k =>
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate i (k:=⟨k, by admit /- proof elided -/
⟩)) ^ (Nat.getBit k j)) | lemma even_index_intermediate_novel_basis_decomposition (i : Fin ℓ) (j : Fin (2 ^ (ℓ - i - 1))) :
intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ ⟨j * 2, by
apply mul_two_add_bit_lt_two_pow j (ℓ-i-1) (ℓ-i) ⟨0, by omega⟩ (by omega) (by omega)
⟩ = (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by omega⟩ ⟨j, by
apply lt_two_pow_of_lt_two_pow_exp_le j (ℓ-i-1) (ℓ-(i+1)) (by omega) (by omega)
⟩).comp (qMap 𝔽q β ⟨i, by omega⟩) := | := by
unfold intermediateNovelBasisX
rw [prod_comp]
-- ∏ k ∈ Fin (ℓ - i), (Wₖ⁽ⁱ⁾(X))^((2j)ₖ) = ∏ k ∈ Fin (ℓ - (i+1)), (Wₖ⁽ⁱ⁺¹⁾(X))^((j)ₖ) ∘ q⁽ⁱ⁾(X)
simp only [pow_comp]
conv_rhs =>
enter [2, x]
rw [intermediateNormVpoly_comp_qmap_helper 𝔽q]
-- ⊢ ∏ x, intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, ⋯⟩ x ^ Nat.getBit (↑x) (↑j * 2) =
-- ∏ x, intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, ⋯⟩ ⟨↑x + 1, ⋯⟩ ^ Nat.getBit ↑x ↑j
set fleft := fun x : Fin (ℓ - ↑i) =>
intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate ⟨↑i, by omega⟩
⟨x, by simp only; omega⟩ ^ Nat.getBit (↑x) (↑j * 2)
have h_n_shift: ℓ - (↑i + 1) + 1 = ℓ - ↑i := by omega
have h_fin_n_shift: Fin (ℓ - (↑i + 1) + 1) = Fin (ℓ - ↑i) := by
rw [h_n_shift]
have h_left_prod_shift :=
Fin.prod_univ_succ (M:=L[X]) (n:=ℓ - (↑i + 1)) (f:=fun x => fleft ⟨x, by omega⟩)
have h_lhs_prod_eq: ∏ x : Fin (ℓ - ↑i),
fleft x = ∏ x : Fin (ℓ - (↑i + 1) + 1), fleft ⟨x, by omega⟩ := by
exact Eq.symm (Fin.prod_congr' fleft h_n_shift)
rw [←h_lhs_prod_eq] at h_left_prod_shift
rw [h_left_prod_shift]
have fleft_0_eq_0: fleft ⟨(0: Fin (ℓ - (↑i + 1) + 1)), by omega⟩ = 1 := by
unfold fleft
simp only
have h_exp: Nat.getBit (0: Fin (ℓ - (↑i + 1) + 1)) (↑j * 2) = 0 := by
simp only [Fin.coe_ofNat_eq_mod, Nat.zero_mod]
have res := Nat.getBit_zero_of_two_mul (n:=j.val)
rw [mul_comm] at res
exact res
rw [h_exp]
simp only [pow_zero]
rw [fleft_0_eq_0, one_mul]
apply Finset.prod_congr rfl
intro x hx
simp only [Fin.val_succ]
unfold fleft
simp only
have h_exp_eq: Nat.getBit (↑x + 1) (↑j * 2) = Nat.getBit ↑x ↑j := by
have h_num_eq: j.val * 2 = 2 * j.val := by omega
rw [h_num_eq]
apply Nat.getBit_eq_succ_getBit_of_mul_two (k:=↑x) (n:=↑j)
rw [h_exp_eq] | 5 | 50 | false | Applied verif. |
21 | ConcreteBinaryTower.split_algebraMap_eq_zero_x | lemma split_algebraMap_eq_zero_x {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField (k - 1)) :
letI instAlgebra := ConcreteBTFieldAlgebra (l:=k-1) (r:=k) (h_le:=by omega)
split h_pos (algebraMap (ConcreteBTField (k - 1)) (ConcreteBTField k) x) = (0, x) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "Ne.dite_eq_left_iff",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.add_one_sub_one",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.left_eq_add",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "RingHom.comp_id",
"module": "Mathlib.Algebra.Ring.Hom.Defs"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le | lemma split_algebraMap_eq_zero_x {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField (k - 1)) :
letI instAlgebra := | := ConcreteBTFieldAlgebra (l:=k-1) (r:=k) (h_le:=by omega)
split h_pos (algebraMap (ConcreteBTField (k - 1)) (ConcreteBTField k) x) = (0, x) := by
-- this one is long because of the `cast` stuff, but it should be quite straightforward
-- via def of `canonicalAlgMap` and `split_of_join`
apply Eq.symm
letI instAlgebra := ConcreteBTFieldAlgebra (l:=k-1) (r:=k) (h_le:=by omega)
set mappedVal := algebraMap (ConcreteBTField (k - 1)) (ConcreteBTField k) x
have h := split_of_join (k:=k) (h_pos:=by omega) (x:=mappedVal)
(hi_btf:=zero (k:=k-1)) (lo_btf:=x)
apply h
-- ⊢ mappedVal = join h_pos zero x
unfold mappedVal
rw [algebraMap, Algebra.algebraMap]
unfold instAlgebra ConcreteBTFieldAlgebra
rw [AlgebraTower.toAlgebra, AlgebraTower.algebraMap, instAlgebraTowerConcreteBTF]
simp only
have h_concrete_embedding_succ_1 := concreteTowerAlgebraMap_succ_1 (k:=k-1)
rw! (castMode:=.all) [Nat.sub_one_add_one (by omega)] at h_concrete_embedding_succ_1
rw! (castMode:=.all) [h_concrete_embedding_succ_1]
rw [eqRec_eq_cast]
rw [ConcreteBTField.RingHom_cast_dest_apply (f:=canonicalAlgMap (k - 1))
(x:=x) (h_eq:=by omega)]
have h_k_sub_1_add_1 : k - 1 + 1 = k := by omega
conv_lhs => enter [2]; rw! (castMode:=.all) [h_k_sub_1_add_1]; simp only
rw [eqRec_eq_cast, eqRec_eq_cast, cast_cast, cast_eq]
rw [ConcreteBTField.RingHom_cast_dest_apply (k:=k - 1) (m:=k - 1 + 1) (n:=k)
(h_eq:=by omega) (f:=canonicalAlgMap (k - 1)) (x:=x)]
simp only [canonicalAlgMap, concreteCanonicalEmbedding, RingHom.coe_mk, MonoidHom.coe_mk,
OneHom.coe_mk]
rw [cast_join (k:=k - 1 + 1) (h_pos:=by omega) (n:=k) (heq:=by omega)]
simp only [Nat.add_one_sub_one, cast_eq, cast_cast] | 8 | 229 | false | Applied verif. |
22 | ConcreteBinaryTower.split_bitvec_eq_iff_fromNat | theorem split_bitvec_eq_iff_fromNat {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField k)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
split h_pos x = (hi_btf, lo_btf) ↔
(hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) ∧
lo_btf = fromNat (k:=k - 1) (x.toNat &&& (2 ^ (2 ^ (k - 1)) - 1))) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
}
] | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dcast h_width_eq (BitVec.ofNat l val) = BitVec.ofNat r val"
},
{
"name": "ConcreteBinaryTower.one_le_sub_middle_of_pow2",
"content": "lemma one_le_sub_midd... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/ | theorem split_bitvec_eq_iff_fromNat {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField k)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
split h_pos x = (hi_btf, lo_btf) ↔
(hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) ∧
lo_btf = fromNat (k:=k - 1) (x.toNat &&& (2 ^ (2 ^ (k - 1)) - 1))) := | := by
have lhs_lo_case := BitVec.extractLsb_eq_and_pow_2_minus_1_ofNat (num_bits:=2 ^ (k - 1))
(n:=2 ^ k) (Nat.two_pow_pos (k - 1)) (x:=x)
have rhs_hi_case_bitvec_eq := BitVec.extractLsb_eq_shift_ofNat (n:=2 ^ k) (r:=2 ^ k - 1)
(l:=2 ^ (k - 1)) (x:=x)
constructor
· -- Forward direction : split x = (hi_btf, lo_btf) → bitwise operations
intro h_split
unfold split at h_split
have ⟨h_hi, h_lo⟩ := Prod.ext_iff.mp h_split
simp only at h_hi h_lo
have hi_eq : hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) := by
unfold fromNat
rw [←h_hi]
rw [dcast_symm (h_sub_middle h_pos).symm]
rw [rhs_hi_case_bitvec_eq]
rw [BitVec.dcast_bitvec_eq]
have lo_eq : lo_btf = fromNat (k:=k - 1) (x.toNat &&& ((2 ^ (2 ^ (k - 1)) - 1))) := by
unfold fromNat
rw [←h_lo]
have rhs_lo_case_bitvec_eq :=
BitVec.extractLsb_eq_shift_ofNat (n:=2 ^ k) (r:=2 ^ (k - 1) - 1) (l:=0) (x:=x)
rw [dcast_symm (h_middle_sub).symm]
rw [rhs_lo_case_bitvec_eq]
rw [BitVec.dcast_bitvec_eq] -- remove dcast
rw [←lhs_lo_case]
exact rhs_lo_case_bitvec_eq
exact ⟨hi_eq, lo_eq⟩
· -- Backward direction : bitwise operations → split x = (hi_btf, lo_btf)
intro h_bits
unfold split
have ⟨h_hi, h_lo⟩ := h_bits
have hi_extract_eq : dcast (h_sub_middle h_pos) (BitVec.extractLsb (hi := 2 ^ k - 1)
(lo := 2 ^ (k - 1)) x) = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) := by
unfold fromNat
rw [dcast_symm (h_sub_middle h_pos).symm]
rw [rhs_hi_case_bitvec_eq]
rw [BitVec.dcast_bitvec_eq]
have lo_extract_eq : dcast (h_middle_sub) (BitVec.extractLsb (hi := 2 ^ (k - 1) - 1)
(lo := 0) x) = fromNat (k:=k - 1) (x.toNat &&& ((2 ^ (2 ^ (k - 1)) - 1))) := by
unfold fromNat
rw [lhs_lo_case]
rw [BitVec.dcast_bitvec_eq]
simp only [hi_extract_eq, Nat.sub_zero, lo_extract_eq, Nat.and_two_pow_sub_one_eq_mod, h_hi,
h_lo] | 4 | 40 | false | Applied verif. |
23 | AdditiveNTT.basisVectors_span | theorem basisVectors_span (ℓ : Nat) (h_ℓ : ℓ ≤ r) :
Submodule.span L (Set.range (basisVectors 𝔽q β ℓ h_ℓ)) = ⊤ | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "WithBot",
"module": "Mathlib.Order.TypeTags"
},
{
"name": "Subspace",
"module": "Mathli... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "finiteDimensional_degreeLT",
"content": "instance finiteDimensional_degreeLT {n : ℕ} (h_n_pos : 0 < n) :\n FiniteDimensional L L⦃< n⦄[X] :="
},
{
"name": "coeff.{u}",
"content": "def coeff... | [
{
"name": "Fin.card_Ico",
"module": "Mathlib.Order.Interval.Finset.Fin"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fintype.card_ofFinset",
"module": "Mathlib.Data.Fintype.Card"
},
{
"name": "LinearIndependent.injective",
"module"... | [
{
"name": "getBit_repr",
"content": "theorem getBit_repr {ℓ : Nat} : ∀ j, j < 2^ℓ →\n j = ∑ k ∈ Finset.Icc 0 (ℓ-1), (getBit k j) * 2^k"
},
{
"name": "getBit_of_shiftRight",
"content": "lemma getBit_of_shiftRight {n p : ℕ}:\n ∀ k, getBit k (n >>> p) = getBit (k+p) n"
},
{
"name": "getBi... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.normalizedW",
"conten... | [
{
"name": "AdditiveNTT.finrank_U",
"content": "omit [Fintype L] [Fintype 𝔽q] h_Fq_char_prime in\nlemma finrank_U (i : Fin r) :\n Module.finrank 𝔽q (U 𝔽q β i) = i"
},
{
"name": "AdditiveNTT.U_card",
"content": "lemma U_card (i : Fin r) :\n Fintype.card (U 𝔽q β i) = (Fintype.card 𝔽q)^i.va... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
noncomputable def normalizedW (i : Fin r) : L[X] :=
C (1 / (W 𝔽q β i).eval (β i)) * W 𝔽q β i
end LinearityOfSubspaceVanishingPolynomials
section NovelPolynomialBasisProof
noncomputable def basisVectors (ℓ : Nat) (h_ℓ : ℓ ≤ r) :
Fin (2 ^ ℓ) → L⦃<2^ℓ⦄[X] :=
fun j => ⟨Xⱼ 𝔽q β ℓ h_ℓ j, by admit /- proof elided -/
⟩
abbrev CoeffVecSpace (L : Type u) (ℓ : Nat) := Fin (2^ℓ) → L
def toCoeffsVec (ℓ : Nat) : L⦃<2^ℓ⦄[X] →ₗ[L] CoeffVecSpace L ℓ where
toFun := fun p => fun i => p.val.coeff i.val
map_add' := fun p q => by admit /- proof elided -/
noncomputable def changeOfBasisMatrix (ℓ : Nat) (h_ℓ : ℓ ≤ r) : Matrix (Fin (2^ℓ)) (Fin (2^ℓ)) L :=
fun j i => (toCoeffsVec (L := L) (ℓ := ℓ) (
basisVectors 𝔽q β ℓ h_ℓ j)) i | theorem basisVectors_span (ℓ : Nat) (h_ℓ : ℓ ≤ r) :
Submodule.span L (Set.range (basisVectors 𝔽q β ℓ h_ℓ)) = ⊤ := | := by
have h_li := basisVectors_linear_independent 𝔽q β ℓ h_ℓ
let n := 2 ^ ℓ
have h_n: n = 2 ^ ℓ := by omega
have h_n_pos: 0 < n := by
rw [h_n]
exact Nat.two_pow_pos ℓ
have h_finrank_eq_n : Module.finrank L (L⦃< n⦄[X]) = n := finrank_degreeLT_n n
-- We have `n` linearly independent vectors in an `n`-dimensional space.
-- The dimension of their span is `n`.
have h_span_finrank : Module.finrank L (Submodule.span L (Set.range (
basisVectors 𝔽q β ℓ h_ℓ))) = n := by
rw [finrank_span_eq_card h_li, Fintype.card_fin]
-- A subspace with the same dimension as the ambient space must be the whole space.
rw [←h_finrank_eq_n] at h_span_finrank
have inst_finite_dim : FiniteDimensional (K := L) (V := L⦃< n⦄[X]) :=
finiteDimensional_degreeLT (h_n_pos := by omega)
apply Submodule.eq_top_of_finrank_eq (K := L) (V := L⦃< n⦄[X])
exact h_span_finrank | 9 | 163 | false | Applied verif. |
24 | MlPoly.coeff_of_toMvPolynomial_eq_coeff_of_MlPoly | theorem coeff_of_toMvPolynomial_eq_coeff_of_MlPoly (p : MlPoly R n) (m : Fin n →₀ ℕ) :
coeff m (toMvPolynomial p) =
if h_binary: (∀ j: Fin n, m j ≤ 1) then
let i_of_m: ℕ := Nat.binaryFinMapToNat (m:=m) (h_binary:=h_binary)
p[i_of_m]
else
0 | ArkLib | ArkLib/Data/MlPoly/Equiv.lean | [
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.MlPoly.Basic",
"import ArkLib.Data.MvPolynomial.Notation"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.univ",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Finsupp",
"module": "Mathlib.Data... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "MlPoly",
"content": "@[reducible]\ndef MlPoly (R : Type*) (n : ℕ) := Vector R (2 ^ n) "
},
{
"name": "binaryFinMapToNat",
"content": "def binaryFinMapToNat {n : ℕ} (m : Fin n → ℕ) (h_binary... | [
{
"name": "Finsupp.onFinset_apply",
"module": "Mathlib.Data.Finsupp.Defs"
},
{
"name": "Fintype.sum_eq_zero",
"module": "Mathlib.Data.Fintype.BigOperators"
},
{
"name": "MvPolynomial.coeff_monomial",
"module": "Mathlib.Algebra.MvPolynomial.Basic"
},
{
"name": "MvPolynomial.co... | [
{
"name": "getBit_lt_2",
"content": "lemma getBit_lt_2 {k n : Nat} : getBit k n < 2"
},
{
"name": "eq_iff_eq_all_getBits",
"content": "lemma eq_iff_eq_all_getBits {n m : ℕ} : n = m ↔ ∀ k, getBit k n = getBit k m"
},
{
"name": "getBit_of_lt_two_pow",
"content": "lemma getBit_of_lt_two... | [
{
"name": "MlPoly.monomialOfNat",
"content": "noncomputable def monomialOfNat (i : ℕ) : (Fin n) →₀ ℕ :=\n Finsupp.onFinset (s:=Finset.univ (α:=Fin n)) (fun j => Nat.getBit j.val i) (by admit /- proof elided -/\n )"
},
{
"name": "MlPoly.toMvPolynomial",
"content": "def toMvPolynomial (p : MlP... | [
{
"name": "MlPoly.eq_monomialOfNat_iff_eq_bitRepr",
"content": "theorem eq_monomialOfNat_iff_eq_bitRepr (m : Fin n →₀ ℕ)\n (h_binary : ∀ j : Fin n, m j ≤ 1) (i: Fin (2^n)) :\n monomialOfNat i = m ↔ i = Nat.binaryFinMapToNat m h_binary"
},
{
"name": "MlPoly.toMvPolynomial_is_multilinear",
"cont... | import ArkLib.Data.MlPoly.Basic
import ArkLib.Data.MvPolynomial.Notation
open MvPolynomial
variable {R : Type*} [CommRing R] {n : ℕ}
noncomputable section
namespace MlPoly
noncomputable def monomialOfNat (i : ℕ) : (Fin n) →₀ ℕ :=
Finsupp.onFinset (s:=Finset.univ (α:=Fin n)) (fun j => Nat.getBit j.val i) (by admit /- proof elided -/
)
def toMvPolynomial (p : MlPoly R n) : R[X Fin n] :=
∑ i : Fin (2 ^ n), MvPolynomial.monomial (monomialOfNat i) (a:=p[i]) | theorem coeff_of_toMvPolynomial_eq_coeff_of_MlPoly (p : MlPoly R n) (m : Fin n →₀ ℕ) :
coeff m (toMvPolynomial p) =
if h_binary: (∀ j: Fin n, m j ≤ 1) then
let i_of_m: ℕ := | := Nat.binaryFinMapToNat (m:=m) (h_binary:=h_binary)
p[i_of_m]
else
0
:= by
if h_binary: (∀ j: Fin n, m j ≤ 1) then
unfold toMvPolynomial
simp only [h_binary, implies_true, ↓reduceDIte]
let i_of_m := Nat.binaryFinMapToNat m h_binary
have h_mono_eq : monomialOfNat i_of_m = m := by
ext j; simp only [monomialOfNat, Finsupp.onFinset_apply]
have h_getBit := Nat.getBit_of_binaryFinMapToNat (n:=n) (m:=m)
(h_binary:=h_binary) (k:=j)
rw [h_getBit]
simp only [j.isLt, ↓reduceDIte, Fin.eta]
rw [MvPolynomial.coeff_sum]
simp only [MvPolynomial.coeff_monomial]
-- ⊢ (∑ x, if monomialOfNat ↑x = m then p[x] else 0) = p[↑(Nat.binaryFinMapToNat ⇑m ⋯)]
set f := fun x: Fin (2^n) => if monomialOfNat x.val = m then p[x] else (0: R)
-- ⊢ Finset.univ.sum f = p[↑(Nat.binaryFinMapToNat ⇑m ⋯)]
rw [Finset.sum_eq_single (a:=⟨i_of_m, by omega⟩)]
· -- Goal 1: Prove the main term is correct.
simp only [h_mono_eq, ↓reduceIte, Fin.eta, Fin.getElem_fin];
rfl
· -- Goal 2: Prove all other terms are zero.
intro j h_j_mem_univ h_ji_ne
-- If `j ≠ i_of_m`, then `monomialOfNat j ≠ monomialOfNat i_of_m` (which is `m`).
-- ⊢ (monomial (monomialOfNat ↑j)) p[j] = 0
have h_mono_ne : monomialOfNat j.val ≠ m := by
intro h_eq_contra
have h_j_is_i_of_m := eq_monomialOfNat_iff_eq_bitRepr (m:=m)
(h_binary:=h_binary) (i:=j).mp h_eq_contra
exact h_ji_ne h_j_is_i_of_m
simp only [h_mono_ne, ↓reduceIte]
-- Goal 3: Prove `i` is in the summation set.
· simp [Finset.mem_univ]
else -- this case is similar to the proof of `right_inv` in `equivMvPolynomialDeg1`
simp only [h_binary, ↓reduceDIte]
-- ⊢ coeff m p.toMvPolynomial = 0
have hv := toMvPolynomial_is_multilinear p
let vMlPoly: R⦃≤ 1⦄[X Fin n] := ⟨p.toMvPolynomial, hv⟩
have h_v_coeff_zero : vMlPoly.val.coeff m = 0 := by
refine notMem_support_iff.mp ?_
by_contra h_mem_support
have hvMlPoly := vMlPoly.2
rw [MvPolynomial.mem_restrictDegree] at hvMlPoly
have h_deg_le_one: ∀ j: Fin n, (m j) ≤ 1 := by
exact fun j ↦ hvMlPoly m h_mem_support j
simp only [not_forall, not_le] at h_binary -- h_binary : ∃ x, 1 < m x
obtain ⟨j, hj⟩ := h_binary
have h_not_1_lt_m_j: ¬(1 < m j) := by exact Nat.not_lt.mpr (hv h_mem_support j)
exact h_not_1_lt_m_j hj
exact h_v_coeff_zero | 6 | 57 | false | Applied verif. |
25 | Polynomial.Bivariate.degreeX_mul | @[simp, grind _=_]
lemma degreeX_mul [IsDomain F] (f g : F[X][Y]) (hf : f ≠ 0) (hg : g ≠ 0) :
degreeX (f * g) = degreeX f + degreeX g | ArkLib | ArkLib/Data/Polynomial/Bivariate.lean | [
"import ArkLib.Data.Polynomial.Prelims"
] | [
{
"name": "Semiring",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "IsDomain",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"nam... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Finset.sum_eq_single",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_union",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sup_lt_iff",
"module": "Mathlib.Data.Finset.Lattice.Fold"
},
{
"name... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Polynomial.Bivariate.coeff",
"content": "def coeff.{u} {F : Type u} [Semiring F] (f : F[X][Y]) (i j : ℕ) : F := (f.coeff j).coeff i"
},
{
"name": "Polynomial.Bivariate.degreeX",
"content": "def degreeX (f : F[X][Y]) : ℕ := f.support.sup (fun n => (f.coeff n).natDegree)"
}
] | [
{
"name": "Polynomial.Bivariate.natDeg_sum_eq_of_unique",
"content": "lemma natDeg_sum_eq_of_unique {α : Type} {s : Finset α} {f : α → F[X]} {deg : ℕ}\n (mx : α) (h : mx ∈ s) :\n (f mx).natDegree = deg →\n (∀ y ∈ s, y ≠ mx → (f y).natDegree < deg ∨ f y = 0) →\n (∑ x ∈ s, f x).natDegree = deg"
},... | import ArkLib.Data.Polynomial.Prelims
open Polynomial
open Polynomial.Bivariate
namespace Polynomial.Bivariate
noncomputable section
variable {F : Type} [Semiring F]
def coeff.{u} {F : Type u} [Semiring F] (f : F[X][Y]) (i j : ℕ) : F := (f.coeff j).coeff i
def degreeX (f : F[X][Y]) : ℕ := f.support.sup (fun n => (f.coeff n).natDegree)
variable {f : F[X][Y]}
open Univariate in
open Classical in | @[simp, grind _=_]
lemma degreeX_mul [IsDomain F] (f g : F[X][Y]) (hf : f ≠ 0) (hg : g ≠ 0) :
degreeX (f * g) = degreeX f + degreeX g := | := by
letI s₁ := {n ∈ f.support | (f.coeff n).natDegree = degreeX f}
letI s₂ := {n ∈ g.support | (g.coeff n).natDegree = degreeX g}
have f_mdeg_nonempty : s₁.Nonempty := by
obtain ⟨mfx, _, _⟩ :=
Finset.exists_mem_eq_sup _ (show f.support.Nonempty by grind) fun n ↦ (f.coeff n).natDegree
use mfx
grind [degreeX]
have g_mdeg_nonempty : s₂.Nonempty := by
obtain ⟨mfx, _, _⟩ :=
Finset.exists_mem_eq_sup _ (show g.support.Nonempty by grind) fun n ↦ (g.coeff n).natDegree
use mfx
grind [degreeX]
set mmfx := s₁.max' f_mdeg_nonempty with hmmfx
set mmgx := s₂.max' g_mdeg_nonempty with hmmgx
have mmfx_def : (f.coeff mmfx).natDegree = degreeX f := by
have h := Finset.max'_mem _ f_mdeg_nonempty
grind
have mmgx_def : (g.coeff mmgx).natDegree = degreeX g := by
have h := Finset.max'_mem _ g_mdeg_nonempty
grind
have h₁ : mmfx ∈ s₁ := Finset.max'_mem _ f_mdeg_nonempty
have h₂ : mmgx ∈ s₂ := Finset.max'_mem _ g_mdeg_nonempty
have mmfx_neq_0 : f.coeff mmfx ≠ 0 := by grind
have mmgx_neq_0 : g.coeff mmgx ≠ 0 := by grind
have h₁ {n} : (f.coeff n).natDegree ≤ degreeX f := by
have : degreeX f = (f.coeff mmfx).natDegree := by grind
by_cases h : n ∈ f.toFinsupp.support
· convert Finset.sup_le_iff.mp (le_of_eq this) n h
· simp [Polynomial.notMem_support_iff.1 h]
have h₂ {n} : (g.coeff n).natDegree ≤ (g.coeff mmgx).natDegree := by
have : degreeX g = (g.coeff mmgx).natDegree := by grind
by_cases h : n ∈ g.toFinsupp.support
· convert Finset.sup_le_iff.mp (le_of_eq this) n h
· simp [Polynomial.notMem_support_iff.1 h]
have h₁' {n} (h : mmfx < n) :
(f.coeff n).natDegree < (f.coeff mmfx).natDegree ∨ f.coeff n = 0 := by
suffices f.coeff n ≠ 0 → (f.coeff mmfx).natDegree ≤ (f.coeff n).natDegree → False by grind
intros h' contra
have : (f.coeff mmfx).natDegree = (f.coeff n).natDegree := by grind
have : n ≤ mmfx := Finset.le_sup'_of_le (hb := show n ∈ s₁ by grind) (h := by simp)
grind
have h₂' {n} (h : mmgx < n) :
(g.coeff n).natDegree < (g.coeff mmgx).natDegree ∨ g.coeff n = 0 := by
suffices g.coeff n ≠ 0 → (g.coeff mmgx).natDegree ≤ (g.coeff n).natDegree → False by grind
intros h' contra
have : (g.coeff mmgx).natDegree = (g.coeff n).natDegree := by grind
have : n ≤ mmgx := Finset.le_sup'_of_le (hb := show n ∈ s₂ by grind) (h := by simp)
grind
unfold degreeX
have : (fun n ↦ ((f * g).coeff n).natDegree) =
fun n ↦ (∑ x ∈ Finset.antidiagonal n, f.coeff x.1 * g.coeff x.2).natDegree := by
funext n; rw [Polynomial.coeff_mul]
rw [this]
have : (∑ x ∈ Finset.antidiagonal (mmfx + mmgx), f.coeff x.1 * g.coeff x.2).natDegree =
degreeX f + degreeX g := by
apply natDeg_sum_eq_of_unique (mmfx, mmgx) (by simp) (by grind)
rintro ⟨y₁, y₂⟩ h h'
have : mmfx < y₁ ∨ mmgx < y₂ := by
have h_anti : y₁ + y₂ = mmfx + mmgx := by simpa using h
grind [mul_eq_zero]
grind [mul_eq_zero]
apply sup_eq_of_le_of_reach (mmfx + mmgx) _ this
swap
· rw [Polynomial.mem_support_iff, Polynomial.coeff_mul]
by_contra h
rw [h, natDegree_zero] at this
have : ∑ x ∈ Finset.antidiagonal (mmfx + mmgx), f.coeff x.1 * g.coeff x.2 =
f.coeff mmfx * g.coeff mmgx := by
apply Finset.sum_eq_single
(f := (fun x ↦ f.coeff x.1 * g.coeff x.2)) (mmfx, mmgx) (h₁ := by simp)
rintro ⟨b₁, b₂⟩ h h'
have : mmfx < b₁ ∨ mmgx < b₂ := by
have h_anti : b₁ + b₂ = mmfx + mmgx := by simpa using h
have fdegx_eq_0 : degreeX f = 0 := by grind
have gdegx_eq_0 : degreeX g = 0 := by grind
grind [mul_eq_zero]
grind [mul_eq_zero]
grind [zero_eq_mul]
· intros x h
apply le_trans
(Polynomial.natDegree_sum_le (Finset.antidiagonal x) (fun x ↦ f.coeff x.1 * g.coeff x.2))
rw [Finset.fold_max_le]
grind [degreeX] | 2 | 34 | false | Applied verif. |
26 | Binius.BinaryBasefold.card_qMap_total_fiber | omit [CharP L 2] [DecidableEq 𝔽q] hF₂ h_β₀_eq_1 [NeZero ℓ] in
theorem card_qMap_total_fiber (i : Fin ℓ) (steps : ℕ) (h_i_add_steps : i.val + steps ≤ ℓ)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by omega⟩)) :
Fintype.card (Set.image (qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by simp only; exact fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps)
(y := y)) Set.univ) = 2 ^ steps | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Prelude.lean | [
"import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound",
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import ArkLib.Data.MvPolynomial.Multilinear",
"import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\... | [
{
"name": "Fin.eta",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "add_zero",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Module.Basis.repr_linearCombination",
"module": "Mathlib.LinearAlgebra.Basis.Defs"
},
{
"name": "Module.Basis.repr_symm_apply",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "lt_add_of_pos_right_of_le",
"content": "@[simp]\nlemma lt_add_of_pos_right_of_le (a b c : ℕ) [NeZero c] (h : a ≤ b) : a < b + c"
},
{
... | [
{
"name": "Binius.BinaryBasefold.fiber_coeff",
"content": "noncomputable def fiber_coeff\n (i : Fin r) (steps : ℕ)\n (j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))\n (y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=\n if hj : j.val < steps then\n if Nat.getBit (k := j) (n := elemen... | [
{
"name": "Binius.BinaryBasefold.fin_ℓ_steps_lt_ℓ_add_R",
"content": "omit [NeZero ℓ] in\nlemma fin_ℓ_steps_lt_ℓ_add_R (i : Fin ℓ) (steps : ℕ) (h : i.val + steps ≤ ℓ)\n : i.val + steps < ℓ + 𝓡"
},
{
"name": "Binius.BinaryBasefold.qMap_total_fiber_repr_coeff",
"content": "lemma qMap_total_fib... | import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch
import ArkLib.Data.CodingTheory.ReedSolomon
import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.MvPolynomial.Multilinear
import ArkLib.Data.Vector.Basic
import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
section Preliminaries
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
end Preliminaries
noncomputable section -- expands with 𝔽q in front
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L] [CharP L 2]
variable (𝔽q : Type) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ 𝓡 ϑ : ℕ} (γ_repetitions : ℕ) [NeZero ℓ] [NeZero 𝓡] [NeZero ϑ] -- Should we allow ℓ = 0?
variable {h_ℓ_add_R_rate : ℓ + 𝓡 < r} -- ℓ ∈ {1, ..., r-1}
variable {𝓑 : Fin 2 ↪ L}
section Essentials
noncomputable def fiber_coeff
(i : Fin r) (steps : ℕ)
(j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))
(y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=
if hj : j.val < steps then
if Nat.getBit (k := j) (n := elementIdx) = 0 then 0 else 1
else y_coeffs ⟨j.val - steps, by admit /- proof elided -/
⟩
noncomputable def qMap_total_fiber
(i : Fin r) (steps : ℕ) (h_i_add_steps : i.val + steps < ℓ + 𝓡)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by admit /- proof elided -/
⟩)) :
Fin (2 ^ steps) → sDomain 𝔽q β h_ℓ_add_R_rate i :=
if h_steps : steps = 0 then by
subst h_steps
simp only [add_zero, Fin.eta] at y
exact fun _ => y
else by
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate (i := ⟨i+steps,by admit /- proof elided -/
⟩) (by admit /- proof elided -/
)
let y_coeffs : Fin (ℓ + 𝓡 - (↑i + steps)) →₀ 𝔽q := basis_y.repr y
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ (by admit /- proof elided -/
)
exact fun elementIdx => by admit /- proof elided -/ | omit [CharP L 2] [DecidableEq 𝔽q] hF₂ h_β₀_eq_1 [NeZero ℓ] in
theorem card_qMap_total_fiber (i : Fin ℓ) (steps : ℕ) (h_i_add_steps : i.val + steps ≤ ℓ)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by omega⟩)) :
Fintype.card (Set.image (qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by simp only; exact fin_ℓ_steps_lt_ℓ_add_R i steps h_i_add_steps)
(y := y)) Set.univ) = 2 ^ steps := | := by
-- The cardinality of the image of a function equals the cardinality of its domain
-- if it is injective.
rw [Set.card_image_of_injective Set.univ]
-- The domain is `Fin (2 ^ steps)`, which has cardinality `2 ^ steps`.
· -- ⊢ Fintype.card ↑Set.univ = 2 ^ steps
simp only [Fintype.card_setUniv, Fintype.card_fin]
· -- prove that `qMap_total_fiber` is an injective function.
intro k₁ k₂ h_eq
-- Assume two indices `k₁` and `k₂` produce the same point `x`.
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ (by simp only; omega)
-- If the points are equal, their basis representations must be equal.
set fiberMap := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y)
have h_coeffs_eq : basis_x.repr (fiberMap k₁) = basis_x.repr (fiberMap k₂) := by
rw [h_eq]
-- The first `steps` coefficients are determined by the bits of `k₁` and `k₂`.
-- If the coefficients are equal, the bits must be equal.
have h_bits_eq : ∀ j : Fin steps,
Nat.getBit (k := j) (n := k₁.val) = Nat.getBit (k := j) (n := k₂.val) := by
intro j
have h_coeff_j_eq : basis_x.repr (fiberMap k₁) ⟨j, by simp only; omega⟩
= basis_x.repr (fiberMap k₂) ⟨j, by simp only; omega⟩ := by rw [h_coeffs_eq]
rw [qMap_total_fiber_repr_coeff 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := h_i_add_steps) (y := y) (j := ⟨j, by simp only; omega⟩)]
at h_coeff_j_eq
rw [qMap_total_fiber_repr_coeff 𝔽q β (i := ⟨i, by omega⟩) (steps := steps)
(h_i_add_steps := h_i_add_steps) (y := y) (k := k₂) (j := ⟨j, by simp only; omega⟩)]
at h_coeff_j_eq
simp only [fiber_coeff, Fin.is_lt, ↓reduceDIte] at h_coeff_j_eq
by_cases hbitj_k₁ : Nat.getBit (k := j) (n := k₁.val) = 0
· simp only [hbitj_k₁, ↓reduceIte, left_eq_ite_iff, zero_ne_one, imp_false,
Decidable.not_not] at ⊢ h_coeff_j_eq
simp only [h_coeff_j_eq]
· simp only [hbitj_k₁, ↓reduceIte, right_eq_ite_iff, one_ne_zero,
imp_false] at ⊢ h_coeff_j_eq
have b1 : Nat.getBit (k := j) (n := k₁.val) = 1 := by
have h := Nat.getBit_eq_zero_or_one (k := j) (n := k₁.val)
simp only [hbitj_k₁, false_or] at h
exact h
have b2 : Nat.getBit (k := j) (n := k₂.val) = 1 := by
have h := Nat.getBit_eq_zero_or_one (k := j) (n := k₂.val)
simp only [h_coeff_j_eq, false_or] at h
exact h
simp only [b1, b2]
-- Extract the j-th coefficient from h_coeffs_eq and show it implies the bits are equal.
-- If all the bits of two numbers are equal, the numbers themselves are equal.
apply Fin.eq_of_val_eq
-- ⊢ ∀ {n : ℕ} {i j : Fin n}, ↑i = ↑j → i = j
apply eq_iff_eq_all_getBits.mpr
intro k
by_cases h_k : k < steps
· simp only [h_bits_eq ⟨k, by omega⟩]
· -- The bits at positions ≥ steps must be deterministic
conv_lhs => rw [Nat.getBit_of_lt_two_pow]
conv_rhs => rw [Nat.getBit_of_lt_two_pow]
simp only [h_k, ↓reduceIte] | 5 | 78 | false | Applied verif. |
27 | Binius.BinaryBasefold.qMap_total_fiber_one_level_eq | lemma qMap_total_fiber_one_level_eq (i : Fin ℓ) (h_i_add_1 : i.val + 1 ≤ ℓ)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i + 1, by omega⟩)) (k : Fin 2) :
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ (by simp only; omega)
let x : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩)
(steps := 1) (h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y) k
let y_lifted : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ := sDomain.lift 𝔽q β h_ℓ_add_R_rate
(i := ⟨i, by omega⟩) (j := ⟨i.val + 1, by omega⟩)
(h_j := by apply Nat.lt_add_of_pos_right_of_le; omega)
(h_le := by apply Fin.mk_le_mk.mpr (by omega)) y
let free_coeff_term : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ :=
(Fin2ToF2 𝔽q k) • (basis_x ⟨0, by simp only; omega⟩)
x = free_coeff_term + y_lifted | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Prelude.lean | [
"import ArkLib.Data.MvPolynomial.Multilinear",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.CodingTheory.ReedSolomon",
"import ArkLib.Data.Vector.Basic",
"import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound",
"import ArkLib.Data.FieldThe... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Ring",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "sDomain",
"content": "noncomputable def sDomain (i : Fin r) : Subspace 𝔽q L :=\n let W_i_norm := normalizedW 𝔽q β i\n let h_W_i_norm_is_additive : IsLinearMap 𝔽q (fun x : L => W_i_norm.eval x) :=\... | [
{
"name": "Fin.eta",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "add_zero",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Module.Basis.repr_linearCombination",
"module": "Mathlib.LinearAlgebra.Basis.Defs"
},
{
"name": "Module.Basis.repr_symm_apply",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "lt_add_of_pos_right_of_le",
"content": "@[simp]\nlemma lt_add_of_pos_right_of_le (a b c : ℕ) [NeZero c] (h : a ≤ b) : a < b + c"
},
{
... | [
{
"name": "Binius.BinaryBasefold.Fin2ToF2",
"content": "def Fin2ToF2 (𝔽q : Type*) [Ring 𝔽q] (k : Fin 2) : 𝔽q :=\n if k = 0 then 0 else 1"
},
{
"name": "Binius.BinaryBasefold.fiber_coeff",
"content": "noncomputable def fiber_coeff\n (i : Fin r) (steps : ℕ)\n (j : Fin (ℓ + 𝓡 - i)) (elem... | [
{
"name": "Binius.BinaryBasefold.fin_ℓ_steps_lt_ℓ_add_R",
"content": "omit [NeZero ℓ] in\nlemma fin_ℓ_steps_lt_ℓ_add_R (i : Fin ℓ) (steps : ℕ) (h : i.val + steps ≤ ℓ)\n : i.val + steps < ℓ + 𝓡"
},
{
"name": "Binius.BinaryBasefold.qMap_total_fiber_repr_coeff",
"content": "lemma qMap_total_fib... | import ArkLib.Data.CodingTheory.BerlekampWelch.BerlekampWelch
import ArkLib.Data.CodingTheory.ReedSolomon
import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.MvPolynomial.Multilinear
import ArkLib.Data.Vector.Basic
import ArkLib.ProofSystem.Sumcheck.Spec.SingleRound
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
section Preliminaries
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
end Preliminaries
noncomputable section -- expands with 𝔽q in front
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L] [CharP L 2]
variable (𝔽q : Type) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ 𝓡 ϑ : ℕ} (γ_repetitions : ℕ) [NeZero ℓ] [NeZero 𝓡] [NeZero ϑ] -- Should we allow ℓ = 0?
variable {h_ℓ_add_R_rate : ℓ + 𝓡 < r} -- ℓ ∈ {1, ..., r-1}
variable {𝓑 : Fin 2 ↪ L}
section Essentials
def Fin2ToF2 (𝔽q : Type*) [Ring 𝔽q] (k : Fin 2) : 𝔽q :=
if k = 0 then 0 else 1
noncomputable def fiber_coeff
(i : Fin r) (steps : ℕ)
(j : Fin (ℓ + 𝓡 - i)) (elementIdx : Fin (2 ^ steps))
(y_coeffs : Fin (ℓ + 𝓡 - (i + steps)) →₀ 𝔽q) : 𝔽q :=
if hj : j.val < steps then
if Nat.getBit (k := j) (n := elementIdx) = 0 then 0 else 1
else y_coeffs ⟨j.val - steps, by admit /- proof elided -/
⟩
noncomputable def qMap_total_fiber
(i : Fin r) (steps : ℕ) (h_i_add_steps : i.val + steps < ℓ + 𝓡)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i.val + steps, by admit /- proof elided -/
⟩)) :
Fin (2 ^ steps) → sDomain 𝔽q β h_ℓ_add_R_rate i :=
if h_steps : steps = 0 then by
subst h_steps
simp only [add_zero, Fin.eta] at y
exact fun _ => y
else by
let basis_y := sDomain_basis 𝔽q β h_ℓ_add_R_rate (i := ⟨i+steps,by admit /- proof elided -/
⟩) (by admit /- proof elided -/
)
let y_coeffs : Fin (ℓ + 𝓡 - (↑i + steps)) →₀ 𝔽q := basis_y.repr y
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by admit /- proof elided -/
⟩ (by admit /- proof elided -/
)
exact fun elementIdx => by admit /- proof elided -/ | lemma qMap_total_fiber_one_level_eq (i : Fin ℓ) (h_i_add_1 : i.val + 1 ≤ ℓ)
(y : sDomain 𝔽q β h_ℓ_add_R_rate (i := ⟨i + 1, by omega⟩)) (k : Fin 2) :
let basis_x := | := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ (by simp only; omega)
let x : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ := qMap_total_fiber 𝔽q β (i := ⟨i, by omega⟩)
(steps := 1) (h_i_add_steps := by apply Nat.lt_add_of_pos_right_of_le; omega) (y := y) k
let y_lifted : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ := sDomain.lift 𝔽q β h_ℓ_add_R_rate
(i := ⟨i, by omega⟩) (j := ⟨i.val + 1, by omega⟩)
(h_j := by apply Nat.lt_add_of_pos_right_of_le; omega)
(h_le := by apply Fin.mk_le_mk.mpr (by omega)) y
let free_coeff_term : sDomain 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ :=
(Fin2ToF2 𝔽q k) • (basis_x ⟨0, by simp only; omega⟩)
x = free_coeff_term + y_lifted
:= by
let basis_x := sDomain_basis 𝔽q β h_ℓ_add_R_rate ⟨i, by omega⟩ (by simp only; omega)
apply basis_x.repr.injective
simp only [map_add, map_smul]
simp only [Module.Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, basis_x]
ext j
have h_repr_x := qMap_total_fiber_repr_coeff 𝔽q β i (steps := 1) (by omega)
(y := y) (k := k) (j := j)
simp only [h_repr_x, Finsupp.coe_add, Pi.add_apply]
simp only [fiber_coeff, lt_one_iff, reducePow, Fin2ToF2, Fin.isValue]
by_cases hj : j = ⟨0, by omega⟩
· simp only [hj, ↓reduceDIte, Fin.isValue, Finsupp.single_eq_same]
by_cases hk : k = 0
· simp only [getBit, hk, Fin.isValue, Fin.coe_ofNat_eq_mod, zero_mod, shiftRight_zero,
and_one_is_mod, ↓reduceIte, zero_add]
-- => Now use basis_repr_of_sDomain_lift
simp only [basis_repr_of_sDomain_lift, add_tsub_cancel_left, zero_lt_one, ↓reduceDIte]
· have h_k_eq_1 : k = 1 := by omega
simp only [getBit, h_k_eq_1, Fin.isValue, Fin.coe_ofNat_eq_mod, mod_succ, shiftRight_zero,
Nat.and_self, one_ne_zero, ↓reduceIte, left_eq_add]
simp only [basis_repr_of_sDomain_lift, add_tsub_cancel_left, zero_lt_one, ↓reduceDIte]
· have hj_ne_zero : j ≠ ⟨0, by omega⟩ := by omega
have hj_val_ne_zero : j.val ≠ 0 := by
change j.val ≠ ((⟨0, by omega⟩ : Fin (ℓ + 𝓡 - ↑i)).val)
apply Fin.val_ne_of_ne
exact hj_ne_zero
simp only [hj_val_ne_zero, ↓reduceDIte, Finsupp.single, Fin.isValue, ite_eq_left_iff,
one_ne_zero, imp_false, Decidable.not_not, Pi.single, Finsupp.coe_mk, Function.update,
hj_ne_zero, Pi.zero_apply, zero_add]
simp only [basis_repr_of_sDomain_lift, add_tsub_cancel_left, lt_one_iff, right_eq_dite_iff]
intro hj_eq_zero
exact False.elim (hj_val_ne_zero hj_eq_zero) | 5 | 95 | false | Applied verif. |
28 | ReedSolomonCode.minDist | theorem minDist [Field F] [DecidableEq F] (inj : Function.Injective α) [NeZero n] (h : n ≤ m) :
minDist ((ReedSolomon.code ⟨α, inj⟩ n) : Set (Fin m → F)) = m - n + 1 | ArkLib | ArkLib/Data/CodingTheory/ReedSolomon.lean | [
"import ArkLib.Data.CodingTheory.Basic",
"import Mathlib.LinearAlgebra.Lagrange",
"import ArkLib.Data.MvPolynomial.LinearMvExtension",
"import Mathlib.RingTheory.Henselian",
"import ArkLib.Data.CodingTheory.Prelims",
"import ArkLib.Data.Fin.Lift",
"import ArkLib.Data.Polynomial.Interface"
] | [
{
"name": "Fintype",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Polynomial.X",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Semiring",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "toFun",
"module": "ToMathlib.Control.Monad.Hom"
},
{
"... | [
{
"name": "wt",
"content": "def wt [Zero F]\n (v : ι → F) : ℕ := #{i | v i ≠ 0}"
},
{
"name": "dim",
"content": "noncomputable def dim [Semiring F] (LC : LinearCode ι F) : ℕ :=\n Module.finrank F LC"
},
{
"name": "LinearCode.{u,",
"content": "abbrev LinearCode.{u, v} (ι : Type u) [... | [
{
"name": "Finset.image_subset_iff",
"module": "Mathlib.Data.Finset.Image"
},
{
"name": "Finset.sum_image",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_le_sum",
"module": "Mathlib.Algebra.Order.BigOperators.Group.Finset"
},
{
"name": "... | [
{
"name": "rank_eq_if_det_ne_zero",
"content": "lemma rank_eq_if_det_ne_zero {U : Matrix (Fin n) (Fin n) F} [IsDomain F] :\n Matrix.det U ≠ 0 → U.rank = n"
},
{
"name": "rank_eq_if_subUpFull_eq",
"content": "lemma rank_eq_if_subUpFull_eq (h : n ≤ m) :\n (subUpFull U (Fin.castLE h)).rank = n ... | [
{
"name": "ReedSolomon.evalOnPoints",
"content": "def evalOnPoints [Semiring F] : F[X] →ₗ[F] (ι → F) where\n toFun := fun p => fun x => p.eval (domain x)\n map_add' := fun x y => by admit /- proof elided -/"
},
{
"name": "ReedSolomon.code",
"content": "def code (deg : ℕ) [Semiring F]: Submodul... | [
{
"name": "Vandermonde.nonsquare_mulVecLin",
"content": "lemma nonsquare_mulVecLin [CommSemiring F] {ι' : ℕ} {α₁ : ι ↪ F} {α₂ : Fin ι' → F} {i : ι} :\n (nonsquare ι' α₁).mulVecLin α₂ i = ∑ x, α₂ x * α₁ i ^ x.1"
},
{
"name": "Vandermonde.subUpFull_of_vandermonde_is_vandermonde",
"content": "lemm... | import ArkLib.Data.MvPolynomial.LinearMvExtension
import ArkLib.Data.Polynomial.Interface
import Mathlib.LinearAlgebra.Lagrange
import Mathlib.RingTheory.Henselian
namespace ReedSolomon
open Polynomial NNReal
variable {F : Type*} {ι : Type*} (domain : ι ↪ F)
def evalOnPoints [Semiring F] : F[X] →ₗ[F] (ι → F) where
toFun := fun p => fun x => p.eval (domain x)
map_add' := fun x y => by admit /- proof elided -/
def code (deg : ℕ) [Semiring F]: Submodule F (ι → F) :=
(Polynomial.degreeLT F deg).map (evalOnPoints domain)
variable [Semiring F]
end ReedSolomon
open Polynomial Matrix Code LinearCode
variable {F ι ι' : Type*}
{C : Set (ι → F)}
noncomputable section
namespace Vandermonde
def nonsquare [Semiring F] (ι' : ℕ) (α : ι → F) : Matrix ι (Fin ι') F :=
Matrix.of fun i j => (α i) ^ j.1
section
variable [CommRing F] {m n : ℕ} {α : Fin m → F}
section
variable [IsDomain F]
end
end
end Vandermonde
namespace ReedSolomonCode
section
open Finset Function
open scoped BigOperators
variable {ι : Type*} [Fintype ι] [Nonempty ι]
{F : Type*} [Field F] [Fintype F]
abbrev RScodeSet (domain : ι ↪ F) (deg : ℕ) : Set (ι → F) := (ReedSolomon.code domain deg).carrier
open Classical in
def toFinset (domain : ι ↪ F) (deg : ℕ) : Finset (ι → F) :=
(RScodeSet domain deg).toFinset
end
section
variable {deg m n : ℕ} {α : Fin m → F}
section
variable [Semiring F] {p : F[X]}
end
open LinearCode
section
open NNReal
variable [Field F]
end
section
def constantCode {α : Type*} (x : α) (ι' : Type*) [Fintype ι'] : ι' → α := fun _ ↦ x
variable [Semiring F] {x : F} [Fintype ι] {α : ι ↪ F}
end
open Finset in | theorem minDist [Field F] [DecidableEq F] (inj : Function.Injective α) [NeZero n] (h : n ≤ m) :
minDist ((ReedSolomon.code ⟨α, inj⟩ n) : Set (Fin m → F)) = m - n + 1 := | := by
have : NeZero m := by constructor; aesop
refine le_antisymm ?p₁ ?p₂
case p₁ =>
have distUB := singletonBound (LC := ReedSolomon.code ⟨α, inj⟩ n)
rw [dim_eq_deg_of_le inj h] at distUB
simp at distUB
zify [dist_le_length] at distUB
omega
case p₂ =>
rw [dist_eq_minWtCodewords]
apply le_csInf (by use m, constantCode 1 _; simp)
intro b ⟨msg, ⟨p, p_deg, p_eval_on_α_eq_msg⟩, msg_neq_0, wt_c_eq_b⟩
let zeroes : Finset _ := {i | msg i = 0}
have eq₁ : zeroes.val.Nodup := by
aesop (add simp [Multiset.nodup_iff_count_eq_one, Multiset.count_filter])
have msg_zeros_lt_deg : #zeroes < n := by
apply lt_of_le_of_lt (b := p.roots.card)
(hbc := lt_of_le_of_lt (Polynomial.card_roots' _)
(natDegree_lt_of_mem_degreeLT p_deg))
exact card_le_card_of_count_inj inj fun i ↦
if h : msg i = 0
then suffices 0 < Multiset.count (α i) p.roots by
rwa [@Multiset.count_eq_one_of_mem (d := eq₁) (h := by simpa [zeroes])]
by aesop
else by simp [zeroes, h]
have : #zeroes + wt msg = m := by
rw [wt, filter_card_add_filter_neg_card_eq_card]
simp
omega | 8 | 118 | false | Applied verif. |
29 | Vector.foldl_succ | theorem foldl_succ
{α β} {n : ℕ} [NeZero n] (f : β → α → β) (init : β) (v : Vector α n) :
v.foldl (f:=f) (b:=init) = v.tail.foldl (f:=f) (b:=f init v.head) | ArkLib | ArkLib/Data/Vector/Basic.lean | [
"import Mathlib.Data.Matrix.Mul",
"import Mathlib.Algebra.Order.Sub.Basic",
"import Mathlib.Algebra.Order.Star.Basic",
"import Mathlib.Algebra.BigOperators.Fin",
"import ToMathlib.General"
] | [
{
"name": "NeZero",
"module": "Init.Data.NeZero"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "Array",
"module": "Init.Prelude"
},
{
"name": "Array.foldl",
"module": "Init.Data.Array.Basic"
},
{
"name": "List",
"module": "Init.Prelude... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Array.foldl_toList",
"module": "Init.Data.Array.Bootstrap"
},
{
"name": "Array.toList_extract",
"module": "Init.Data.Array.Lemmas"
},
{
"name": "List.drop_one",
"module": "Init.Data.List.TakeDrop"
},
{
"name": "List.extract_eq_drop_take",
"module": "Init.Data.L... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [] | [] | import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Algebra.Order.Sub.Basic
import Mathlib.Data.Matrix.Mul
import ToMathlib.General
namespace Vector | theorem foldl_succ
{α β} {n : ℕ} [NeZero n] (f : β → α → β) (init : β) (v : Vector α n) :
v.foldl (f:=f) (b:=init) = v.tail.foldl (f:=f) (b:=f init v.head) := | := by
simp_rw [Vector.foldl] -- get
simp only [size_toArray]
have hl_foldl_eq_toList_foldl := Array.foldl_toList (f:=f) (init:=init) (xs:=v.toArray)
have hl_foldl_eq: Array.foldl f init v.toArray 0 n = Array.foldl f init v.toArray := by
simp only [size_toArray]
conv_lhs =>
rw [hl_foldl_eq, hl_foldl_eq_toList_foldl.symm]
have hr_foldl_eq_toList_foldl_tail := Array.foldl_toList (f:=f) (init:=f init v.head)
(xs:=(v.tail.toArray))
have hr_foldl_eq: Array.foldl f (f init v.head) v.tail.toArray 0 (n - 1)
= Array.foldl f (f init v.head) v.tail.toArray := by
simp only [size_toArray] -- Array.foldl_congr
conv_rhs =>
rw [hr_foldl_eq, hr_foldl_eq_toList_foldl_tail.symm]
rw [Vector.head]
have h_v_toList_length: 0 < v.toList.length := by
simp only [length_toList]
exact Nat.pos_of_neZero n
rw [←Vector.getElem_toList (h:=h_v_toList_length)]
have h_toList_eq: v.toArray.toList = v.toList := rfl
rw [Vector.tail]
simp only [toArray_cast, toArray_extract, Array.toList_extract, List.extract_eq_drop_take,
List.drop_one]
simp_rw [h_toList_eq]
-- ⊢ List.foldl f init v.toList
-- = List.foldl f (f init v.toList[0]) (List.take (n - 1) v.toList.tail)
have hTakeTail: List.take (n - 1) v.toList.tail = v.toList.tail := by
simp only [List.take_eq_self_iff, List.length_tail, length_toList, le_refl]
rw [hTakeTail]
have h_v_eq_cons: v.toList = v.head :: (v.toList.tail) := by
cases h_list : v.toList with
| nil =>
have h_len : v.toList.length = 0 := by rw [h_list, List.length_nil]
omega
| cons hd tl =>
have h_v_head: v.head = v.toList[0] := rfl
simp_rw [h_v_head]
have h_hd: hd = v.toList[0] := by simp only [h_list, List.getElem_cons_zero]
simp only [List.tail_cons, List.cons.injEq, and_true]
simp_rw [h_hd]
conv_lhs => rw [h_v_eq_cons]
rw [List.foldl_cons]
rfl | 1 | 29 | true | Applied verif. |
30 | ConcreteBinaryTower.join_eq_bitvec_iff_fromNat | theorem join_eq_bitvec_iff_fromNat {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField k)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
x = 《 hi_btf, lo_btf 》 ↔
(hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) ∧
lo_btf = fromNat (k:=k - 1) (x.toNat &&& (2 ^ (2 ^ (k - 1)) - 1))) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "AlgebraTowerEquiv.symm",
"content": "def AlgebraTowerEquiv.symm (e : AlgebraTowerEquiv A B) : AlgebraTowerEquiv... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dcast (Eq.refl n) bv = bv"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k := | theorem join_eq_bitvec_iff_fromNat {k : ℕ} (h_pos : k > 0) (x : ConcreteBTField k)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
x = 《 hi_btf, lo_btf 》 ↔
(hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) ∧
lo_btf = fromNat (k:=k - 1) (x.toNat &&& (2 ^ (2 ^ (k - 1)) - 1))) := | := by
-- Idea : derive from theorem join_eq_iff_dcast_extractLsb
constructor
· -- Forward direction
intro h_join
have h := join_eq_iff_dcast_extractLsb h_pos x hi_btf lo_btf
have ⟨h_hi, h_lo⟩ := h.mp h_join
have hi_eq : hi_btf = fromNat (k:=k - 1) (x.toNat >>> 2 ^ (k - 1)) := by
rw [h_hi]
have := BitVec.extractLsb_eq_shift_ofNat (n:=2 ^ k) (r:=2 ^ k - 1) (l:=2 ^ (k - 1)) (x:=x)
rw [this]
unfold fromNat
rw [BitVec.dcast_bitvec_eq]
have lo_eq : lo_btf = fromNat (k:=k - 1) (x.toNat &&& (2 ^ (2 ^ (k - 1)) - 1)) := by
rw [h_lo]
have := BitVec.extractLsb_eq_and_pow_2_minus_1_ofNat (num_bits:=2 ^ (k - 1)) (n:=2 ^ k)
(Nat.two_pow_pos (k - 1)) (x:=x)
rw [this]
unfold fromNat
rw [BitVec.dcast_bitvec_eq]
exact ⟨hi_eq, lo_eq⟩
· -- Backward direction
intro h_bits
have ⟨h_hi, h_lo⟩ := h_bits
have h := join_eq_iff_dcast_extractLsb h_pos x hi_btf lo_btf
have hi_eq : hi_btf = dcast (h_sub_middle h_pos)
(BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x) := by
rw [h_hi]
unfold fromNat
have := BitVec.extractLsb_eq_shift_ofNat (n:=2 ^ k) (r:=2 ^ k - 1) (l:=2 ^ (k - 1)) (x:=x)
rw [this]
rw [BitVec.dcast_bitvec_eq]
have lo_eq : lo_btf = dcast (h_middle_sub)
(BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x) := by
rw [h_lo]
unfold fromNat
have := BitVec.extractLsb_eq_and_pow_2_minus_1_ofNat (num_bits:=2 ^ (k - 1)) (n:=2 ^ k)
(Nat.two_pow_pos (k - 1)) (x:=x)
rw [this]
rw [BitVec.dcast_bitvec_eq]
exact h.mpr ⟨hi_eq, lo_eq⟩ | 6 | 94 | false | Applied verif. |
31 | ConcreteBinaryTower.split_one | lemma split_one {k : ℕ} (h_k : k > 0) :
split h_k (one (k:=k)) = (zero (k:=k - 1), one (k:=k - 1)) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
}
] | [
{
"name": "Nat.ne_zero_of_lt",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.one_lt_two_pow_iff",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "Nat.shiftRight_eq_zero",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "BitVec.toNat_ofNat",
"module": "Init.Data.Bi... | [
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ): 1 ≤ 2^(n+1) - 2^n"
},
{
"name": "zero_lt_pow_n",
"content": "theorem zero_lt_pow_n (m : ℕ)... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dcast h_width_eq (BitVec.ofNat l val) = BitVec.ofNat r val"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq_zero",
"content": "theorem BitVec.dcas... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/ | lemma split_one {k : ℕ} (h_k : k > 0) :
split h_k (one (k:=k)) = (zero (k:=k - 1), one (k:=k - 1)) := | := by
rw [split]
let lo_bits := BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) (one (k:=k))
let hi_bits := BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) (one (k:=k))
apply Prod.ext
· simp only
simp only [BitVec.extractLsb, BitVec.extractLsb']
rw [one]
have one_toNat_eq := one_bitvec_toNat (width:=2 ^ k)
(h_width:=zero_lt_pow_n (m:=2) (n:=k) (h_m:=Nat.zero_lt_two))
rw [one_toNat_eq]
have one_shiftRight_eq : 1 >>> 2 ^ (k - 1) = 0 :=
one_bitvec_shiftRight (d:=2 ^ (k - 1)) (h_d:=by exact Nat.two_pow_pos (k - 1))
rw [one_shiftRight_eq]
rw [zero, BitVec.zero_eq]
have h_sub_middle := sub_middle_of_pow2_with_one_canceled (k:=k) (h_k:=h_k)
rw [BitVec.dcast_bitvec_eq_zero]
· simp only
simp only [BitVec.extractLsb, BitVec.extractLsb']
simp only [Nat.sub_zero, one, BitVec.toNat_ofNat, Nat.ofNat_pos, pow_pos, Nat.one_mod_two_pow,
Nat.shiftRight_zero] -- converts BitVec.toNat one >>> 0 into 1#(2 ^ (k - 1))
rw [BitVec.dcast_bitvec_eq] | 4 | 43 | false | Applied verif. |
32 | AdditiveNTT.W_prod_comp_decomposition | lemma W_prod_comp_decomposition
(i : Fin r) (hi : i > 0) :
(W 𝔽q β i) = ∏ c: 𝔽q, (W 𝔽q β (i-1)).comp (X - C (c • β (i-1))) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Polynomial.splits_X_sub_C",
"module": "Mathlib.Algebra.Polynomial.Splits"
},
{
"name": "Polynomial.splits_prod",
"module": "Mathlib.Algebra.Polynomial.Splits"
},
{
"name": "Finset.prod_eq_zero_iff",
"module": "Mathlib.Algebra.BigOperators.GroupWithZero.Finset"
},
{
... | [
{
"name": "Fin.lt_succ'",
"content": "lemma Fin.lt_succ' (a : Fin r) (h_a_add_1 : a + 1 < r) : a < a + 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
},
{
"name": "Fin.le_succ",
"content": "lemma F... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.algEquivAevalXSubC",
... | [
{
"name": "AdditiveNTT.βᵢ_not_in_Uᵢ",
"content": "lemma βᵢ_not_in_Uᵢ (i : Fin r) :\n β i ∉ U 𝔽q β i"
},
{
"name": "AdditiveNTT.root_U_lift_down",
"content": "omit [Fintype L] [DecidableEq L] [Fintype 𝔽q] h_Fq_char_prime in\ntheorem root_U_lift_down\n (i : Fin r) (h_i_add_1 : i + 1 < r) (a ... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
@[simps!]
noncomputable def algEquivAevalXSubC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := | lemma W_prod_comp_decomposition
(i : Fin r) (hi : i > 0) :
(W 𝔽q β i) = ∏ c: 𝔽q, (W 𝔽q β (i-1)).comp (X - C (c • β (i-1))) := | := by
-- ⊢ W 𝔽q β i = ∏ c, (W 𝔽q β (i - 1)).comp (X - C (c • β (i - 1)))
-- Define P and Q for clarity
set P := W 𝔽q β i
set Q := ∏ c: 𝔽q, (W 𝔽q β (i-1)).comp (X - C (c • β (i-1)))
-- c : 𝔽q => univ
-- c ∈ finsetX
-- STRATEGY: Prove P = Q by showing they are monic, split, and have the same roots.
-- 1. Show P and Q are MONIC.
have hP_monic : P.Monic := W_monic (𝔽q := 𝔽q) (β := β) (i :=i)
have hQ_monic : Q.Monic := by
apply Polynomial.monic_prod_of_monic; intro c _
apply Monic.comp
· exact W_monic (𝔽q := 𝔽q) (β := β) (i :=(i-1))
· -- ⊢ (X - C (c • β (i - 1))).Monic
exact Polynomial.monic_X_sub_C (c • β (i - 1))
· conv_lhs => rw [natDegree_sub_C, natDegree_X]
norm_num
-- 2. Show P and Q SPLIT over L.
have hP_splits : P.Splits (RingHom.id L) := W_splits 𝔽q β i
have hQ_splits : Q.Splits (RingHom.id L) := by
apply Polynomial.splits_prod
intro c _
-- Composition of a splitting polynomial with a linear polynomial also splits.
-- ⊢ Splits (RingHom.id L) ((W 𝔽q β (i - 1)).comp (X - C (c • β (i - 1))))
apply Splits.comp_of_degree_le_one
· exact degree_X_sub_C_le (c • β (i - 1))
· -- ⊢ Splits (RingHom.id L) (W 𝔽q β (i - 1))
exact W_splits 𝔽q β (i-1)
-- 3. Show P and Q have the same ROOTS.
have h_roots_eq : P.roots = Q.roots := by
-- First, characterize the roots of P. They are the elements of Uᵢ.
unfold P Q
ext u
rw [Polynomial.count_roots, Polynomial.count_roots]
rw [rootMultiplicity_W]
conv_rhs =>
rw [rootMultiplicity_prod_W_comp_X_sub_C 𝔽q β (h_i_add_1 := by
rw [Fin.val_sub_one (a := i) (h_a_sub_1 := by omega)]
omega
)]
-- ⊢ (if u ∈ ↑(U 𝔽q β i) then 1 else 0) = if u ∈ ↑(U 𝔽q β (i - 1 + 1)) then 1 else 0
have h_i : i - 1 + 1 = i := by simp only [sub_add_cancel]
rw [h_i]
-- 4. CONCLUSION: Since P and Q are monic, split, and have the same roots, they are equal.
have hP_eq_prod := Polynomial.eq_prod_roots_of_monic_of_splits_id hP_monic hP_splits
have hQ_eq_prod := Polynomial.eq_prod_roots_of_monic_of_splits_id hQ_monic hQ_splits
rw [hP_eq_prod, hQ_eq_prod, h_roots_eq] | 5 | 173 | false | Applied verif. |
33 | ConcreteBinaryTower.towerRingHomBackwardMap_forwardMap_eq | lemma towerRingHomBackwardMap_forwardMap_eq (k : ℕ) (x : ConcreteBTField k) :
towerRingHomBackwardMap (k:=k) (towerRingHomForwardMap (k:=k) x) = x | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "BitVec.cast_ofNat",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.ofNat_eq_ofNat",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.eq_zero_or_eq_one",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "congrArg",
"module": "Init.Prelude"
},
... | [
{
"name": "dcast_eq_root_cast",
"content": "theorem dcast_eq_root_cast (h : a = a') : dcast h b = _root_.cast (congrArg β h) b"
},
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : ... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.bitvec_cast_eq_dcast",
"content": "theorem BitVec.bitvec_cast_eq_dcast {n m : Nat} (h :... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le
def join_via_add_smul (k : ℕ) (h_pos : k > 0) (hi_btf lo_btf : ConcreteBTField (k - 1)) :
ConcreteBTField k :=
end ConcreteBTFieldAlgebraConstruction
noncomputable section ConcreteMultilinearBasis
open Module
end ConcreteMultilinearBasis
section TowerEquivalence
open BinaryTower
noncomputable def towerEquiv_zero : RingEquiv (R:=GF(2)) (S:=ConcreteBTField 0) := {
toFun := fun x => if x = 0 then 0 else 1,
invFun := fun x => if x = 0 then 0 else 1,
left_inv := fun x => by admit /- proof elided -/
noncomputable def towerRingEquiv0 : BTField 0 ≃+* ConcreteBTField 0 :=
noncomputable def towerRingEquivFromConcrete0 : ConcreteBTField 0 ≃+* BTField 0 :=
noncomputable def towerRingHomForwardMap (k : ℕ) : ConcreteBTField k → BTField k :=
noncomputable def towerRingHomBackwardMap (k : ℕ) : BTField k → ConcreteBTField k := | lemma towerRingHomBackwardMap_forwardMap_eq (k : ℕ) (x : ConcreteBTField k) :
towerRingHomBackwardMap (k:=k) (towerRingHomForwardMap (k:=k) x) = x := | := by
induction k with
| zero =>
unfold towerRingHomBackwardMap towerRingHomForwardMap
simp only [↓reduceDIte, RingEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe]
rcases concrete_eq_zero_or_eq_one (a:=x) (by omega) with x_zero | x_one
· rw [x_zero, zero_is_0]
unfold towerRingEquivFromConcrete0 -- unfold the inner RingEquiv only
simp only [RingEquiv.apply_symm_apply] -- due to definition of `towerRingEquiv0`
· rw [x_one, one_is_1]
unfold towerRingEquivFromConcrete0 -- unfold the inner RingEquiv only
simp only [RingEquiv.apply_symm_apply] -- due to definition of `towerRingEquiv0`
| succ k ih =>
rw [towerRingHomForwardMap] -- split inner
simp only [Nat.add_eq_zero, one_ne_zero, and_false, ↓reduceDIte, Nat.add_one_sub_one]
rw [towerRingHomBackwardMap] -- split outer
simp only [Nat.add_eq_zero, one_ne_zero, and_false, ↓reduceDIte, Nat.add_one_sub_one]
rw [←join_eq_join_via_add_smul]
apply Eq.symm
apply join_of_split
simp only [Nat.add_one_sub_one]
rw [BinaryTower.split_join_via_add_smul_eq_iff_split (k:=k + 1)]
simp only
-- apply induction hypothesis
rw [ih, ih]
simp only [Prod.mk.eta] | 15 | 299 | false | Applied verif. |
34 | AdditiveNTT.additiveNTT_correctness | theorem additiveNTT_correctness (h_ℓ : ℓ ≤ r)
(original_coeffs : Fin (2 ^ ℓ) → L)
(output_buffer : Fin (2 ^ (ℓ + R_rate)) → L)
(h_alg : output_buffer = additiveNTT 𝔽q β h_ℓ_add_R_rate original_coeffs) :
let P := polynomialFromNovelCoeffs 𝔽q β ℓ h_ℓ original_coeffs
∀ (j : Fin (2^(ℓ + R_rate))),
output_buffer j = P.eval (evaluationPointω 𝔽q β h_ℓ_add_R_rate ⟨0, by omega⟩ j) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Nat.Bitwise",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs",
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "MvPolynomial",
"module": "Mathlib.Algebra.MvPolynomial.Basic"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "MvPolynomial.op... | [
{
"name": "notation:70 s:70 \" ^^ \" t:71 => Fintype.piFinset fun (i : t)",
"content": "notation:70 s:70 \" ^^ \" t:71 => Fintype.piFinset fun (i : t) ↦ s i"
},
{
"name": "macro_rules (kind := mvEval)",
"content": "macro_rules (kind := mvEval)\n | `($p⸨$x⸩) => `(MvPolynomial.eval ($x ∘ Fin.cast... | [
{
"name": "Polynomial.comp_assoc",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "Fin.coe_ofNat_eq_mod",
"module": "Mathlib.Data.Fin.Basic"
},
{
"name": "Fin.foldl_succ",
"module": "Init.Data.Fin.Fol... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "getBit_eq_succ_getBit_of_mul_two_add_one",
"content": "lemma getBit_eq_succ_getBit_of_mul_two_add_one {n k : ℕ} : getBit (k+1) (2*n + 1) = get... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.qCompositi... | [
{
"name": "AdditiveNTT.qMap_eval_𝔽q_eq_0",
"content": "omit [DecidableEq L] [DecidableEq 𝔽q] h_Fq_char_prime hF₂ hβ_lin_indep h_β₀_eq_1 in\ntheorem qMap_eval_𝔽q_eq_0 (i : Fin r) :\n ∀ c: 𝔽q, (qMap 𝔽q β i).eval (algebraMap 𝔽q L c) = 0"
},
{
"name": "AdditiveNTT.qMap_comp_normalizedW",
"con... | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable def qCompositionChain (i : Fin r) : L[X] :=
match i with
| ⟨0, _⟩ => X
| ⟨k + 1, h_k_add_1⟩ => (qMap 𝔽q β ⟨k, by admit /- proof elided -/
⟩).comp (qCompositionChain ⟨k, by admit /- proof elided -/
⟩)
noncomputable section DomainBijection
end DomainBijection
noncomputable def intermediateNormVpoly
(i: Fin (ℓ+1)) (k : Fin (ℓ - i + 1)) : L[X] :=
Fin.foldl (n:=k) (fun acc j =>
(qMap 𝔽q β ⟨(i : ℕ) + (j : ℕ), by admit /- proof elided -/
⟩).comp acc) (X)
noncomputable def intermediateNovelBasisX (i : Fin (ℓ + 1)) (j : Fin (2 ^ (ℓ - i))) : L[X] :=
(Finset.univ: Finset (Fin (ℓ - i)) ).prod (fun k =>
(intermediateNormVpoly 𝔽q β h_ℓ_add_R_rate i (k:=⟨k, by admit /- proof elided -/
⟩)) ^ (Nat.getBit k j))
noncomputable def intermediateEvaluationPoly (i : Fin (ℓ + 1))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i))), C (coeffs ⟨j, by admit /- proof elided -/
⟩) *
(intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate i ⟨j, by admit /- proof elided -/
⟩)
noncomputable def evenRefinement (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i-1))), C (coeffs ⟨j*2, by admit /- proof elided -/
⟩) * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by admit /- proof elided -/
⟩ ⟨j, hj⟩)
noncomputable def oddRefinement (i : Fin (ℓ))
(coeffs : Fin (2 ^ (ℓ - i)) → L) : L[X] :=
∑ (⟨j, hj⟩: Fin (2^(ℓ-i-1))), C (coeffs ⟨j*2+1, by admit /- proof elided -/
⟩) * (intermediateNovelBasisX 𝔽q β h_ℓ_add_R_rate ⟨i+1, by admit /- proof elided -/
⟩ ⟨j, hj⟩)
end IntermediateStructures
section AlgorithmCorrectness
noncomputable def evaluationPointω (i : Fin (ℓ + 1))
(x : Fin (2 ^ (ℓ + R_rate - i))) : L :=
∑ (⟨k, hk⟩: Fin (ℓ + R_rate - i)),
if Nat.getBit k x.val = 1 then
(normalizedW 𝔽q β ⟨i, by admit /- proof elided -/
⟩).eval (β ⟨i + k, by admit /- proof elided -/
⟩)
else
0
noncomputable def twiddleFactor (i : Fin ℓ) (u : Fin (2 ^ (ℓ + R_rate - i - 1))) : L :=
∑ (⟨k, hk⟩: Fin (ℓ + R_rate - i - 1)),
if Nat.getBit k u.val = 1 then
(normalizedW 𝔽q β ⟨i, by admit /- proof elided -/
⟩).eval (β ⟨i + 1 + k, by admit /- proof elided -/
⟩)
else 0
def tileCoeffs (a : Fin (2 ^ ℓ) → L) : Fin (2^(ℓ + R_rate)) → L :=
fun v => a (Fin.mk (v.val % (2^ℓ)) (Nat.mod_lt v.val (pow_pos (zero_lt_two) ℓ)))
noncomputable def NTTStage (i : Fin ℓ) (b : Fin (2 ^ (ℓ + R_rate)) → L) :
Fin (2^(ℓ + R_rate)) → L :=
have h_2_pow_i_lt_2_pow_ℓ_add_R_rate: 2^i.val < 2^(ℓ + R_rate) := by admit /- proof elided -/
noncomputable def additiveNTT (a : Fin (2 ^ ℓ) → L) : Fin (2^(ℓ + R_rate)) → L :=
let b: Fin (2^(ℓ + R_rate)) → L := tileCoeffs a
Fin.foldl (n:=ℓ) (f:= fun current_b i =>
NTTStage 𝔽q β h_ℓ_add_R_rate (i := ⟨ℓ - 1 - i, by admit /- proof elided -/
⟩) current_b
) (init:=b)
def coeffsBySuffix (a : Fin (2 ^ ℓ) → L) (i : Fin (ℓ + 1)) (v : Fin (2 ^ i.val)) :
Fin (2 ^ (ℓ - i)) → L :=
fun ⟨j, hj⟩ => by admit /- proof elided -/
def additiveNTTInvariant (evaluation_buffer : Fin (2 ^ (ℓ + R_rate)) → L)
(original_coeffs : Fin (2 ^ ℓ) → L) (i : Fin (ℓ + 1)) : Prop :=
∀ (j : Fin (2^(ℓ + R_rate))),
let u_b_v := j.val
let v: Fin (2^i.val) := ⟨Nat.getLowBits i.val u_b_v, by admit /- proof elided -/
⟩
let u_b := u_b_v / (2^i.val)
have h_u_b : u_b = u_b_v / (2^i.val) := by admit /- proof elided -/ | theorem additiveNTT_correctness (h_ℓ : ℓ ≤ r)
(original_coeffs : Fin (2 ^ ℓ) → L)
(output_buffer : Fin (2 ^ (ℓ + R_rate)) → L)
(h_alg : output_buffer = additiveNTT 𝔽q β h_ℓ_add_R_rate original_coeffs) :
let P := | := polynomialFromNovelCoeffs 𝔽q β ℓ h_ℓ original_coeffs
∀ (j : Fin (2^(ℓ + R_rate))),
output_buffer j = P.eval (evaluationPointω 𝔽q β h_ℓ_add_R_rate ⟨0, by omega⟩ j) :=
by
simp only [Fin.zero_eta]
intro j
simp only [h_alg]
unfold additiveNTT
set output_foldl := Fin.foldl ℓ (fun current_b i ↦ NTTStage 𝔽q β h_ℓ_add_R_rate
⟨ℓ - i -1, by omega⟩ current_b) (tileCoeffs original_coeffs)
have output_foldl_correctness : additiveNTTInvariant 𝔽q β h_ℓ_add_R_rate
output_foldl original_coeffs ⟨0, by omega⟩ := by
have res := foldl_NTTStage_inductive_aux 𝔽q β h_ℓ_add_R_rate
h_ℓ
(k:=⟨ℓ, by omega⟩) original_coeffs
simp only [tsub_self, Fin.zero_eta] at res
exact res
have h_nat_point_ω_eq_j: j.val / 2 * 2 + j.val % 2 = j := by
have h_j_mod_2_eq_0: j.val % 2 < 2 := by omega
exact Nat.div_add_mod' (↑j) 2
simp only [additiveNTTInvariant] at output_foldl_correctness
have res := output_foldl_correctness j
unfold output_foldl at res
simp only [Fin.zero_eta, Nat.sub_zero, pow_zero, Nat.div_one, Fin.eta,
Nat.pow_zero, Nat.getLowBits_zero_eq_zero (n := j.val), Fin.isValue, base_coeffsBySuffix] at res
simp only [←
intermediate_poly_P_base 𝔽q β h_ℓ_add_R_rate
h_ℓ original_coeffs,
Fin.zero_eta]
rw [←res]
simp_rw [Nat.sub_right_comm] -- ℓ - 1 - ↑i = ℓ - ↑i - 1 | 14 | 317 | false | Applied verif. |
35 | InductiveMerkleTree.functional_completeness | theorem functional_completeness (α : Type) {s : Skeleton}
(idx : SkeletonLeafIndex s)
(leaf_data_tree : LeafData α s)
(hash : α → α → α) :
(getPutativeRoot_with_hash
idx
(leaf_data_tree.get idx)
(generateProof
(buildMerkleTree_with_hash leaf_data_tree hash) idx)
(hash)) =
(buildMerkleTree_with_hash leaf_data_tree hash).getRootValue | ArkLib | ArkLib/CommitmentScheme/InductiveMerkleTree.lean | [
"import ArkLib.ToMathlib.Data.IndexedBinaryTree.Basic",
"import Mathlib.Data.Vector.Snoc",
"import ArkLib.CommitmentScheme.Basic",
"import VCVio",
"import ArkLib.ToVCVio.Oracle"
] | [
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "FullData.leftSubtree",
"content": "def FullData.leftSubtree {α : Type} {s_left s_right : Skeleton}\n (tree : FullData α (Skeleton.internal s_left s_right)) :\n FullData α s_left :=\n match tree with\n | FullData.internal _ left _right =>\n left"
},
{
"name": "Skeleton",
"co... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "LeafData.rightSubtree_internal",
"content": "@[simp]\ntheorem LeafData.rightSubtree_internal {α} {s_left s_right : Skeleton}\n (left : LeafData α s_left) (right : LeafData α s_right) :\n (LeafData.internal left right).rightSubtree = right"
},
{
"name": "LeafData.leftSubtree_internal... | [
{
"name": "InductiveMerkleTree.buildMerkleTree_with_hash",
"content": "def buildMerkleTree_with_hash {s} (leaf_tree : LeafData α s) (hashFn : α → α → α) :\n (FullData α s) :=\n match leaf_tree with\n | LeafData.leaf a => FullData.leaf a\n | LeafData.internal left right =>\n let leftTree := buildMer... | [
{
"name": "InductiveMerkleTree.generateProof_ofLeft",
"content": "@[simp]\ntheorem generateProof_ofLeft {sleft sright : Skeleton}\n (cache_tree : FullData α (Skeleton.internal sleft sright))\n (idxLeft : SkeletonLeafIndex sleft) :\n generateProof cache_tree (BinaryTree.SkeletonLeafIndex.ofLeft idxL... | import VCVio
import ArkLib.ToMathlib.Data.IndexedBinaryTree.Basic
import ArkLib.CommitmentScheme.Basic
import Mathlib.Data.Vector.Snoc
import ArkLib.ToVCVio.Oracle
namespace InductiveMerkleTree
open List OracleSpec OracleComp BinaryTree
section spec
variable (α : Type)
end spec
variable {α : Type}
def buildMerkleTree_with_hash {s} (leaf_tree : LeafData α s) (hashFn : α → α → α) :
(FullData α s) :=
match leaf_tree with
| LeafData.leaf a => FullData.leaf a
| LeafData.internal left right =>
let leftTree := buildMerkleTree_with_hash left hashFn
let rightTree := buildMerkleTree_with_hash right hashFn
let rootHash := hashFn (leftTree.getRootValue) (rightTree.getRootValue)
FullData.internal rootHash leftTree rightTree
def generateProof {s} (cache_tree : FullData α s) :
BinaryTree.SkeletonLeafIndex s → List α
| .ofLeaf => []
| .ofLeft idxLeft =>
(cache_tree.rightSubtree).getRootValue ::
(generateProof cache_tree.leftSubtree idxLeft)
| .ofRight idxRight =>
(cache_tree.leftSubtree).getRootValue ::
(generateProof cache_tree.rightSubtree idxRight)
def getPutativeRoot_with_hash {s} (idx : BinaryTree.SkeletonLeafIndex s)
(leafValue : α) (proof : List α) (hashFn : α → α → α) : α :=
match proof with
| [] => leafValue
| siblingBelowRootHash :: restProof =>
match idx with
| BinaryTree.SkeletonLeafIndex.ofLeaf =>
leafValue
| BinaryTree.SkeletonLeafIndex.ofLeft idxLeft =>
hashFn (getPutativeRoot_with_hash idxLeft leafValue restProof hashFn) siblingBelowRootHash
| BinaryTree.SkeletonLeafIndex.ofRight idxRight =>
hashFn siblingBelowRootHash (getPutativeRoot_with_hash idxRight leafValue restProof hashFn) | theorem functional_completeness (α : Type) {s : Skeleton}
(idx : SkeletonLeafIndex s)
(leaf_data_tree : LeafData α s)
(hash : α → α → α) :
(getPutativeRoot_with_hash
idx
(leaf_data_tree.get idx)
(generateProof
(buildMerkleTree_with_hash leaf_data_tree hash) idx)
(hash)) =
(buildMerkleTree_with_hash leaf_data_tree hash).getRootValue := | := by
induction s with
| leaf =>
match leaf_data_tree with
| LeafData.leaf a =>
cases idx with
| ofLeaf =>
simp [buildMerkleTree_with_hash, getPutativeRoot_with_hash]
| internal s_left s_right left_ih right_ih =>
match leaf_data_tree with
| LeafData.internal left right =>
cases idx with
| ofLeft idxLeft =>
simp_rw [LeafData.get_ofLeft, LeafData.leftSubtree_internal, buildMerkleTree_with_hash,
generateProof_ofLeft, FullData.rightSubtree, FullData.leftSubtree,
getPutativeRoot_with_hash, left_ih, FullData.internal_getRootValue]
| ofRight idxRight =>
simp_rw [LeafData.get_ofRight, LeafData.rightSubtree_internal, buildMerkleTree_with_hash,
generateProof_ofRight, FullData.leftSubtree, FullData.rightSubtree,
getPutativeRoot_with_hash, right_ih, FullData.internal_getRootValue] | 4 | 31 | false | Applied verif. |
36 | ConcreteBinaryTower.aeval_definingPoly_at_Z_succ | lemma aeval_definingPoly_at_Z_succ (k : ℕ) :
(aeval (Z (k + 1))) (definingPoly (s:=Z (k))) = 0 | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dcast (Eq.refl n) bv = bv"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r := | lemma aeval_definingPoly_at_Z_succ (k : ℕ) :
(aeval (Z (k + 1))) (definingPoly (s:=Z (k))) = 0 := | := by
rw [aeval_def]
set f := algebraMap (ConcreteBTField k) (ConcreteBTField (k + 1))
have h_f_is_canonical_embedding :
f = concreteTowerAlgebraMap (l:=k) (r:=k+1) (h_le:=by omega) := by rfl
rw [definingPoly, eval₂_add, eval₂_add] -- break down into sum of terms
rw [eval₂_X_pow]
rw [C_mul']
-- ⊢ Z (k + 1) ^ 2 + eval₂ f (Z (k + 1)) (Z k • X) + eval₂ f (Z (k + 1)) 1 = 0
simp only [eval₂_one, eval₂_smul, eval₂_X]
-- Z_square_mul_form uses instAlgebraLiftConcreteBTField internally
rw [Z_square_mul_form (k:=k) (prev:=(getBTFResult (k:=k)))]
rw [add_assoc]
rw [algebraMap, Algebra.algebraMap, instAlgebraLiftConcreteBTField]
simp only
-- f uses ConcreteBTFieldAlgebra, it's same as instAlgebraLiftConcreteBTField at step = 1
rw [h_f_is_canonical_embedding, concreteTowerAlgebraMap_succ_1]
simp only [canonicalAlgMap]; rw [mul_comm]
rw [add_self_cancel] | 10 | 257 | false | Applied verif. |
37 | AdditiveNTT.inductive_linear_map_W | omit hF₂ in
lemma inductive_linear_map_W (i : Fin r) (h_i_add_1 : i + 1 < r)
(h_prev_linear_map : IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β i).comp inner_p))
: IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β (i + 1)).comp inner_p) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Fact.out",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Fin.le_zero_iff'",
"module": "Mathlib.Data.Fin.SuccPred"
},
{
"name": "LinearIndependent.injective",
"module": "Mathlib.LinearAlgebra.LinearIndependent.Defs"
},
{
"name": "Nat.not_lt_zero",
"module": "Ini... | [
{
"name": "Fin.lt_succ'",
"content": "lemma Fin.lt_succ' (a : Fin r) (h_a_add_1 : a + 1 < r) : a < a + 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
},
{
"name": "Fin.le_succ",
"content": "lemma F... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.algEquivAevalXSubC",
... | [
{
"name": "AdditiveNTT.βᵢ_not_in_Uᵢ",
"content": "lemma βᵢ_not_in_Uᵢ (i : Fin r) :\n β i ∉ U 𝔽q β i"
},
{
"name": "AdditiveNTT.root_U_lift_down",
"content": "omit [Fintype L] [DecidableEq L] [Fintype 𝔽q] h_Fq_char_prime in\ntheorem root_U_lift_down\n (i : Fin r) (h_i_add_1 : i + 1 < r) (a ... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
@[simps!]
noncomputable def algEquivAevalXSubC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := | omit hF₂ in
lemma inductive_linear_map_W (i : Fin r) (h_i_add_1 : i + 1 < r)
(h_prev_linear_map : IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β i).comp inner_p))
: IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β (i + 1)).comp inner_p) := | := by
have h_rec_form := inductive_rec_form_W_comp
(hβ_lin_indep := hβ_lin_indep) (h_prev_linear_map := h_prev_linear_map) (i :=i)
set q := Fintype.card 𝔽q
set v := (W 𝔽q β i).eval (β i)
-- `∀ f(X), f(X) ∈ L[X]`:
constructor
· intro f g
-- 1. Proof flow
-- `Wᵢ₊₁(f(X)+g(X)) = Wᵢ(f(X)+g(X))² - v • Wᵢ(f(X)+g(X))` -- h_rec_form
-- `= (Wᵢ(f(X)) + Wᵢ(g(X)))² - v • (Wᵢ(f(X)) + Wᵢ(g(X)))`
-- `= (Wᵢ(f(X))² + (Wᵢ(g(X)))² - v • Wᵢ(f(X)) - v • Wᵢ(g(X)))` => Freshman's Dream
-- `= (Wᵢ(f(X))² - v • Wᵢ(f(X))) + (Wᵢ(g(X))² - v • Wᵢ(g(X)))` -- h_rec_form
-- `= Wᵢ₊₁(f(X)) + Wᵢ₊₁(g(X))` -- Q.E.D.
-- ⊢ (W 𝔽q β (i + 1)).comp (x + y) = (W 𝔽q β (i + 1)).comp x + (W 𝔽q β (i + 1)).comp y
calc
_ = ((W 𝔽q β i).comp (f + g))^q - C v ^ (q - 1) * ((W 𝔽q β i).comp (f + g)) := by
rw [h_rec_form h_i_add_1]
_ = ((W 𝔽q β i).comp f)^q + ((W 𝔽q β i).comp g)^q
- C v ^ (q - 1) * ((W 𝔽q β i).comp f) - C v ^ (q - 1) * ((W 𝔽q β i).comp g) := by
rw [h_prev_linear_map.map_add]
rw [Polynomial.frobenius_identity_in_algebra]
rw [left_distrib]
unfold q
abel_nf
_ = (((W 𝔽q β i).comp f)^q - C v ^ (q - 1) * ((W 𝔽q β i).comp f))
+ (((W 𝔽q β i).comp g)^q - C v ^ (q - 1) * ((W 𝔽q β i).comp g)) := by
abel_nf
_ = (W 𝔽q β (i+1)).comp f + (W 𝔽q β (i+1)).comp g := by
unfold q
rw [h_rec_form h_i_add_1 f]
rw [h_rec_form h_i_add_1 g]
· intro c f
-- 2. Proof flow
-- `Wᵢ₊₁(c • f(X)) = Wᵢ(c • f(X))² - v • Wᵢ(c • f(X))` -- h_rec_form
-- `= c² • Wᵢ(f(X))² - v • c • Wᵢ(f(X))`
-- `= c • Wᵢ(f(X))² - v • c • Wᵢ(f(X))` via Fermat's Little Theorem (X^q = X)
-- `= c • (Wᵢ(f(X))² - v • Wᵢ(f(X)))` -- h_rec_form
-- `= c • Wᵢ₊₁(f(X))` -- Q.E.D.
have h_c_smul_to_algebraMap_smul: ∀ t: L[X], c • t = (algebraMap 𝔽q L c) • t := by
exact algebra_compatible_smul L c
have h_c_smul_to_C_algebraMap_mul: ∀ t: L[X], c • t = C (algebraMap 𝔽q L c) * t := by
intro t
rw [h_c_smul_to_algebraMap_smul]
exact smul_eq_C_mul ((algebraMap 𝔽q L) c)
-- ⊢ (W 𝔽q β (i + 1)).comp (c • x) = c • (W 𝔽q β (i + 1)).comp x
calc
_ = ((W 𝔽q β i).comp (c • f))^q - C v ^ (q - 1) * ((W 𝔽q β i).comp (c • f)) := by
rw [h_rec_form h_i_add_1 (c • f)]
_ = (C (algebraMap 𝔽q L c) * (W 𝔽q β i).comp f)^q
- C v ^ (q - 1) * (C (algebraMap 𝔽q L c) * (W 𝔽q β i).comp f) := by
rw [h_prev_linear_map.map_smul]
rw [mul_pow]
simp_rw [h_c_smul_to_C_algebraMap_mul]
congr
rw [mul_pow]
_ = C (algebraMap 𝔽q L (c^q)) * ((W 𝔽q β i).comp f)^q
- C v ^ (q - 1) * (C (algebraMap 𝔽q L c) * (W 𝔽q β i).comp f) := by
rw [mul_pow]
congr -- ⊢ C ((algebraMap 𝔽q L) c) ^ q = C ((algebraMap 𝔽q L) (c ^ q))
rw [←C_pow]
simp_rw [algebraMap.coe_pow c q]
_ = C (algebraMap 𝔽q L (c^q)) * ((W 𝔽q β i).comp f)^q
- C v ^ (q - 1) * (C (algebraMap 𝔽q L c) * (W 𝔽q β i).comp f) := by
-- use Fermat's Little Theorem (X^q = X)
simp only [map_pow]
_ = C (algebraMap 𝔽q L (c)) * ((W 𝔽q β i).comp f)^q
- C v ^ (q - 1) * (C (algebraMap 𝔽q L c) * (W 𝔽q β i).comp f) := by
rw [FiniteField.pow_card]
_ = C (algebraMap 𝔽q L c) * (((W 𝔽q β i).comp f)^q
- C v ^ (q - 1) * (W 𝔽q β i).comp f) := by
rw [←mul_assoc]
conv_lhs => rw [mul_comm (a := C v ^ (q - 1)) (b := C (algebraMap 𝔽q L c))]; rw [mul_assoc]
exact
Eq.symm
(mul_sub_left_distrib (C ((algebraMap 𝔽q L) c)) ((W 𝔽q β i).comp f ^ q)
(C v ^ (q - 1) * (W 𝔽q β i).comp f))
_ = C (algebraMap 𝔽q L c) * (W 𝔽q β (i + 1)).comp f := by
rw [h_rec_form h_i_add_1 f]
_ = _ := by
rw [h_c_smul_to_C_algebraMap_mul] | 7 | 238 | false | Applied verif. |
38 | ConcreteBinaryTower.join_eq_join_via_add_smul | @[simp]
theorem join_eq_join_via_add_smul {k : ℕ} (h_pos : k > 0)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
《 hi_btf, lo_btf 》 = join_via_add_smul k h_pos hi_btf lo_btf | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le
def join_via_add_smul (k : ℕ) (h_pos : k > 0) (hi_btf lo_btf : ConcreteBTField (k - 1)) :
ConcreteBTField k := | @[simp]
theorem join_eq_join_via_add_smul {k : ℕ} (h_pos : k > 0)
(hi_btf lo_btf : ConcreteBTField (k - 1)) :
《 hi_btf, lo_btf 》 = join_via_add_smul k h_pos hi_btf lo_btf := | := by
unfold join_via_add_smul
set instAlgebra := ConcreteBTFieldAlgebra (l:=k-1) (r:=k) (h_le:=by omega)
set hi_lifted := instAlgebra.2 hi_btf with h_hi_lifted
-- First, show `hi_btf • Z k` corresponds to `join h_pos hi_btf 0`.
have h_hi_term : hi_btf • Z k = 《 hi_btf, 0 》 := by
apply join_of_split
exact split_smul_Z_eq_zero_x h_pos hi_btf
-- Second, show `algebraMap ... lo_btf` corresponds to `join h_pos 0 lo_btf`.
have h_lo_term : algebraMap (ConcreteBTField (k-1))
(ConcreteBTField k) lo_btf = 《 0, lo_btf 》 := by
have h := join_of_split (x := algebraMap (ConcreteBTField (k-1)) (ConcreteBTField k) lo_btf)
(h_pos:=by omega) (hi_btf:=zero (k:=k-1)) (lo_btf:=lo_btf)
apply h
rw [split_algebraMap_eq_zero_x h_pos lo_btf]
rfl
rw [h_hi_term, h_lo_term]
-- ⊢ join h_pos hi_btf lo_btf = join h_pos hi_btf 0 + join h_pos 0 lo_btf
rw [join_add_join h_pos hi_btf 0 0 lo_btf]
simp only [_root_.add_zero, _root_.zero_add] | 14 | 250 | false | Applied verif. |
39 | AdditiveNTT.W_linearity | theorem W_linearity (i : Fin r)
: IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β i).comp inner_p) | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/NovelPolynomialBasis.lean | [
"import Mathlib.Algebra.Polynomial.Degree.Definitions",
"import ArkLib.Data.Fin.BigOperators",
"import ArkLib.Data.Polynomial.MonomialBasis",
"import Mathlib.LinearAlgebra.StdBasis",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.Polynomial.Frobenius"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "Fin.succRecOnSameFinType",
"content": "@[elab_as_elim] def Fin.succRecOnSameFinType {motive : Fin r → Sort _}\n (zero : motive (0 : Fin r))\n (succ : ∀ i : Fin r, i + 1 < r → motive i → motive (i... | [
{
"name": "Fact.out",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Fin.le_zero_iff'",
"module": "Mathlib.Data.Fin.SuccPred"
},
{
"name": "LinearIndependent.injective",
"module": "Mathlib.LinearAlgebra.LinearIndependent.Defs"
},
{
"name": "Nat.not_lt_zero",
"module": "Ini... | [
{
"name": "Fin.lt_succ'",
"content": "lemma Fin.lt_succ' (a : Fin r) (h_a_add_1 : a + 1 < r) : a < a + 1"
},
{
"name": "Fin.val_add_one'",
"content": "lemma Fin.val_add_one' (a : Fin r) (h_a_add_1 : a + 1 < r) : (a + 1).val = a.val + 1"
},
{
"name": "Fin.le_succ",
"content": "lemma F... | [
{
"name": "AdditiveNTT.U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "AdditiveNTT.W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "AdditiveNTT.algEquivAevalXSubC",
... | [
{
"name": "AdditiveNTT.βᵢ_not_in_Uᵢ",
"content": "lemma βᵢ_not_in_Uᵢ (i : Fin r) :\n β i ∉ U 𝔽q β i"
},
{
"name": "AdditiveNTT.root_U_lift_down",
"content": "omit [Fintype L] [DecidableEq L] [Fintype 𝔽q] h_Fq_char_prime in\ntheorem root_U_lift_down\n (i : Fin r) (h_i_add_1 : i + 1 < r) (a ... | import ArkLib.Data.Nat.Bitwise
import ArkLib.Data.Polynomial.Frobenius
import ArkLib.Data.Polynomial.MonomialBasis
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.Algebra.Polynomial.Degree.Definitions
open Polynomial FiniteDimensional Finset Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (h_dim : Module.finrank 𝔽q L = r)
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
section LinearSubspaces
def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))
noncomputable def W (i : Fin r) : L[X] :=
∏ u : U 𝔽q β i, (X - C u.val)
end LinearSubspaces
section LinearityOfSubspaceVanishingPolynomials
@[simps!]
noncomputable def algEquivAevalXSubC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := | theorem W_linearity (i : Fin r)
: IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β i).comp inner_p) := | := by
induction i using Fin.succRecOnSameFinType with
| zero =>
-- Base Case: i = 0 => Prove W₀ is linear.
unfold W
have h_U0 : (univ : Finset (U 𝔽q β 0)) = {0} := by
ext u -- u : ↥(U 𝔽q β 0)
simp only [mem_univ, true_iff, mem_singleton]
-- ⊢ u = 0
by_contra h
have h_u := u.property
-- only U and Submodule.span_empty is enough for simp
simp only [U, lt_self_iff_false, not_false_eq_true, Set.Ico_eq_empty, Set.image_empty,
Submodule.span_empty, Submodule.mem_bot, ZeroMemClass.coe_eq_zero] at h_u
contradiction
rw [h_U0, prod_singleton, Submodule.coe_zero, C_0, sub_zero]
-- ⊢ IsLinearMap 𝔽q fun x ↦ eval x X
exact { -- can also use `refine` with exact same syntax
map_add := fun x y => by
rw [X_comp, X_comp, X_comp]
map_smul := fun c x => by
rw [X_comp, X_comp]
}
| succ j jh p =>
-- Inductive Step: Assume properties hold for `j`, prove for `j+1`.
have h_linear_map: (IsLinearMap 𝔽q (f := fun inner_p ↦ (W 𝔽q β (j + 1)).comp inner_p)) := by
exact inductive_linear_map_W 𝔽q β (i := j)
(h_i_add_1 := by omega) (h_prev_linear_map := p)
exact h_linear_map | 8 | 257 | false | Applied verif. |
40 | MvPolynomial.finSuccEquivNth_coeff_coeff | theorem finSuccEquivNth_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) :
coeff m (Polynomial.coeff (finSuccEquivNth R p f) i) = coeff (m.insertNth p i) f | ArkLib | ArkLib/ToMathlib/MvPolynomial/Equiv.lean | [
"import Mathlib.Algebra.MvPolynomial.Equiv",
"import ArkLib.ToMathlib.Finsupp.Fin"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "MvPolynomial",
"module": "Mathlib.Algebra.MvPolynomial.Basic"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "MvPolynomial.optionEquivLeft",
"module": "Mathlib.Algebra.MvPolynomi... | [
{
"name": "insertNth",
"content": "def insertNth (p : Fin (n + 1)) (y : M) (s : Fin n →₀ M) : Fin (n + 1) →₀ M :=\n Finsupp.equivFunOnFinite.symm (Fin.insertNth p y s : Fin (n + 1) → M)"
},
{
"name": "removeNth",
"content": "def removeNth (p : Fin (n + 1)) (s : Fin (n + 1) →₀ M) : Fin n →₀ M :=... | [
{
"name": "AlgEquiv.coe_trans",
"module": "Mathlib.Algebra.Algebra.Equiv"
},
{
"name": "Function.comp_apply",
"module": "Init.Core"
},
{
"name": "MvPolynomial.aeval_C",
"module": "Mathlib.Algebra.MvPolynomial.Eval"
},
{
"name": "MvPolynomial.coe_eval₂Hom",
"module": "Math... | [
{
"name": "insertNth_self_removeNth",
"content": "theorem insertNth_self_removeNth : insertNth p (t p) (removeNth p t) = t"
},
{
"name": "insertNth_apply_succAbove",
"content": "@[simp]\ntheorem insertNth_apply_succAbove : insertNth p y s (p.succAbove i) = s i"
},
{
"name": "removeNth_ap... | [
{
"name": "MvPolynomial.finSuccEquivNth",
"content": "def finSuccEquivNth : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) :=\n (renameEquiv R (_root_.finSuccEquiv' p)).trans (optionEquivLeft R (Fin n))"
}
] | [
{
"name": "MvPolynomial.finSuccEquivNth_eq",
"content": "theorem finSuccEquivNth_eq :\n (finSuccEquivNth R p : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) =\n eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R))\n (Fin.insertNth p Polynomial.X (Polynomial.... | import Mathlib.Algebra.MvPolynomial.Equiv
import ArkLib.ToMathlib.Finsupp.Fin
namespace MvPolynomial
open Function Finsupp Polynomial
noncomputable section
section FinSuccEquivNth
variable {n : ℕ} {σ : Type*} (R : Type*) [CommSemiring R] (p : Fin (n + 1))
def finSuccEquivNth : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) :=
(renameEquiv R (_root_.finSuccEquiv' p)).trans (optionEquivLeft R (Fin n))
variable {R} {p} | theorem finSuccEquivNth_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) :
coeff m (Polynomial.coeff (finSuccEquivNth R p f) i) = coeff (m.insertNth p i) f := | := by
induction' f using MvPolynomial.induction_on' with u a p q hp hq generalizing i m
· simp only [finSuccEquivNth_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, comp_apply,
prod_pow, Fin.prod_univ_succAbove _ p, Fin.insertNth_apply_same,
Fin.insertNth_apply_succAbove, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial,
← map_prod, ← RingHom.map_pow]
rw [← mul_boole, mul_comm (Polynomial.X ^ u p), Polynomial.coeff_C_mul_X_pow]; congr 1
obtain rfl | hjmi := eq_or_ne u (m.insertNth p i)
· simpa only [insertNth_apply_same, if_pos rfl, insertNth_apply_succAbove, monomial_eq, C_1,
one_mul, prod_pow] using coeff_monomial m m (1 : R)
· simp only [hjmi, if_false]
obtain hij | rfl := ne_or_eq i (u p)
· simp only [hij, if_false, coeff_zero]
simp only [eq_self_iff_true, if_true]
have hmj : m ≠ u.removeNth p := by
rintro rfl
rw [insertNth_self_removeNth] at hjmi
contradiction
simpa only [monomial_eq, C_1, one_mul, prod_pow, Finsupp.removeNth_apply, if_neg hmj.symm]
using coeff_monomial m (u.removeNth p) (1 : R)
· simp only [map_add, Polynomial.coeff_add, coeff_add, hp, hq] | 3 | 70 | false | Applied verif. |
41 | ReedSolomonCode.genMatIsVandermonde | lemma genMatIsVandermonde [Fintype ι] [Field F] [DecidableEq F] [inst : NeZero m] {α : ι ↪ F} :
fromColGenMat (Vandermonde.nonsquare (ι' := m) α) = ReedSolomon.code α m | ArkLib | ArkLib/Data/CodingTheory/ReedSolomon.lean | [
"import Mathlib.LinearAlgebra.Lagrange",
"import ArkLib.Data.MvPolynomial.LinearMvExtension",
"import Mathlib.RingTheory.Henselian",
"import ArkLib.Data.Fin.Lift",
"import ArkLib.Data.Polynomial.Interface"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Matrix",
"module": "Mathlib.LinearAlgebra.Matrix.Defs"
},
{
"name": "Semiring",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "Matrix.of",
"module": "Mathlib.LinearAlgebra.Matrix.Defs"
},
{
"name": "Poly... | [
{
"name": "polynomialOfCoeffs",
"content": "def polynomialOfCoeffs (coeffs : Fin deg → F) : F[X] :=\n ⟨\n Finset.map ⟨Fin.val, Fin.val_injective⟩ {i | coeffs i ≠ 0},\n fun i ↦ if h : i < deg then coeffs ⟨i, h⟩ else 0,\n fun a ↦ by admit /- proof elided -/\n ⟩"
},
{
"name": "liftF'",
"... | [
{
"name": "Polynomial.mem_degreeLT",
"module": "Mathlib.RingTheory.Polynomial.Basic"
},
{
"name": "Polynomial.natDegree_lt_iff_degree_lt",
"module": "Mathlib.Algebra.Polynomial.Degree.Definitions"
},
{
"name": "Matrix.mulVecLin_apply",
"module": "Mathlib.LinearAlgebra.Matrix.ToLin"
... | [
{
"name": "liftF'_p_coeff",
"content": "@[simp]\nlemma liftF'_p_coeff {p : F[X]} {k : ℕ} {i : Fin k} : liftF' p.coeff i = p.coeff i"
},
{
"name": "coeff_polynomialOfCoeffs_eq_coeffs",
"content": "@[simp]\nlemma coeff_polynomialOfCoeffs_eq_coeffs :\n Fin.liftF' (polynomialOfCoeffs coeffs).coeff ... | [
{
"name": "ReedSolomon.evalOnPoints",
"content": "def evalOnPoints [Semiring F] : F[X] →ₗ[F] (ι → F) where\n toFun := fun p => fun x => p.eval (domain x)\n map_add' := fun x y => by admit /- proof elided -/"
},
{
"name": "ReedSolomon.code",
"content": "def code (deg : ℕ) [Semiring F]: Submodul... | [
{
"name": "Vandermonde.nonsquare_mulVecLin",
"content": "lemma nonsquare_mulVecLin [CommSemiring F] {ι' : ℕ} {α₁ : ι ↪ F} {α₂ : Fin ι' → F} {i : ι} :\n (nonsquare ι' α₁).mulVecLin α₂ i = ∑ x, α₂ x * α₁ i ^ x.1"
},
{
"name": "Vandermonde.mulVecLin_coeff_vandermondens_eq_eval_matrixOfPolynomials",
... | import ArkLib.Data.MvPolynomial.LinearMvExtension
import ArkLib.Data.Polynomial.Interface
import Mathlib.LinearAlgebra.Lagrange
import Mathlib.RingTheory.Henselian
namespace ReedSolomon
open Polynomial NNReal
variable {F : Type*} {ι : Type*} (domain : ι ↪ F)
def evalOnPoints [Semiring F] : F[X] →ₗ[F] (ι → F) where
toFun := fun p => fun x => p.eval (domain x)
map_add' := fun x y => by admit /- proof elided -/
def code (deg : ℕ) [Semiring F]: Submodule F (ι → F) :=
(Polynomial.degreeLT F deg).map (evalOnPoints domain)
variable [Semiring F]
end ReedSolomon
open Polynomial Matrix Code LinearCode
variable {F ι ι' : Type*}
{C : Set (ι → F)}
noncomputable section
namespace Vandermonde
def nonsquare [Semiring F] (ι' : ℕ) (α : ι → F) : Matrix ι (Fin ι') F :=
Matrix.of fun i j => (α i) ^ j.1
section
variable [CommRing F] {m n : ℕ} {α : Fin m → F}
section
variable [IsDomain F]
end
end
end Vandermonde
namespace ReedSolomonCode
section
open Finset Function
open scoped BigOperators
variable {ι : Type*} [Fintype ι] [Nonempty ι]
{F : Type*} [Field F] [Fintype F]
open Classical in
end
section
variable {deg m n : ℕ} {α : Fin m → F}
section
variable [Semiring F] {p : F[X]}
end
open LinearCode | lemma genMatIsVandermonde [Fintype ι] [Field F] [DecidableEq F] [inst : NeZero m] {α : ι ↪ F} :
fromColGenMat (Vandermonde.nonsquare (ι' := m) α) = ReedSolomon.code α m := | := by
unfold fromColGenMat ReedSolomon.code
ext x; rw [LinearMap.mem_range, Submodule.mem_map]
refine ⟨
fun ⟨coeffs, h⟩ ↦ ⟨polynomialOfCoeffs coeffs, h.symm ▸ ?p₁⟩,
fun ⟨p, h⟩ ↦ ⟨Fin.liftF' p.coeff, ?p₂⟩
⟩
· rw [
←coeff_polynomialOfCoeffs_eq_coeffs (coeffs := coeffs),
Vandermonde.mulVecLin_coeff_vandermondens_eq_eval_matrixOfPolynomials (by simp)
]
simp [ReedSolomon.evalOnPoints]
· exact h.2 ▸ Vandermonde.mulVecLin_coeff_vandermondens_eq_eval_matrixOfPolynomials
(natDegree_lt_of_mem_degreeLT h.1) | 3 | 47 | false | Applied verif. |
42 | UniPoly.toImpl_toPoly_of_canonical | lemma toImpl_toPoly_of_canonical [LawfulBEq R] (p : UniPolyC R) : p.toPoly.toImpl = p | ArkLib | ArkLib/Data/UniPoly/Basic.lean | [
"import Mathlib.Algebra.Tropical.Basic",
"import ArkLib.Data.Array.Lemmas",
"import Mathlib.RingTheory.Polynomial.Basic"
] | [
{
"name": "inline",
"module": "Init.Core"
},
{
"name": "Array",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Option",
... | [
{
"name": "findIdxRev?",
"content": "def findIdxRev? (cond : α → Bool) (as : Array α) : Option (Fin as.size) :=\n find ⟨ as.size, Nat.lt_succ_self _ ⟩\nwhere\n find : Fin (as.size + 1) → Option (Fin as.size)\n | 0 => none\n | ⟨ i+1, h ⟩ =>\n if (cond as[i]) then\n some ⟨ i, Nat.lt_of_suc... | [
{
"name": "Nat.lt_succ_self",
"module": "Init.Prelude"
},
{
"name": "Array.foldl_induction",
"module": "Init.Data.Array.Lemmas"
},
{
"name": "Array.getD_eq_getD_getElem?",
"module": "Init.Data.Array.Lemmas"
},
{
"name": "Array.getElem?_eq_none",
"module": "Init.Data.Array... | [
{
"name": "findIdxRev?_eq_some",
"content": "theorem findIdxRev?_eq_some {cond} {as : Array α} (h : ∃ i, ∃ hi : i < as.size, cond as[i]) :\n ∃ k : Fin as.size, findIdxRev? cond as = some k"
},
{
"name": "findIdxRev?_eq_none",
"content": "theorem findIdxRev?_eq_none {cond} {as : Array α} (h : ∀ ... | [
{
"name": "UniPoly",
"content": "@[reducible, inline, specialize]\ndef UniPoly (R : Type*) := Array R"
},
{
"name": "Polynomial.toImpl",
"content": "def Polynomial.toImpl {R : Type*} [Semiring R] (p : R[X]) : UniPoly R :=\n match p.degree with\n | ⊥ => #[]\n | some d => .ofFn (fun i : Fin (d... | [
{
"name": "UniPoly.Trim.last_nonzero_none",
"content": "theorem last_nonzero_none [LawfulBEq R] {p : UniPoly R} :\n (∀ i, (hi : i < p.size) → p[i] = 0) → p.last_nonzero = none"
},
{
"name": "UniPoly.Trim.last_nonzero_some",
"content": "theorem last_nonzero_some [LawfulBEq R] {p : UniPoly R} {i}... | import Mathlib.Algebra.Tropical.Basic
import Mathlib.RingTheory.Polynomial.Basic
import ArkLib.Data.Array.Lemmas
open Polynomial
@[reducible, inline, specialize]
def UniPoly (R : Type*) := Array R
def Polynomial.toImpl {R : Type*} [Semiring R] (p : R[X]) : UniPoly R :=
match p.degree with
| ⊥ => #[]
| some d => .ofFn (fun i : Fin (d + 1) => p.coeff i)
namespace UniPoly
@[reducible]
def mk {R : Type*} (coeffs : Array R) : UniPoly R := coeffs
variable {R : Type*} [Ring R] [BEq R]
variable {Q : Type*} [Ring Q]
@[reducible]
def coeff (p : UniPoly Q) (i : ℕ) : Q := p.getD i 0
def last_nonzero (p : UniPoly R) : Option (Fin p.size) :=
p.findIdxRev? (· != 0)
def trim (p : UniPoly R) : UniPoly R :=
match p.last_nonzero with
| none => #[]
| some i => p.extract 0 (i.val + 1)
def degree (p : UniPoly R) : Nat :=
match p.last_nonzero with
| none => 0
| some i => i.val + 1
namespace Trim
def last_nonzero_prop {p : UniPoly R} (k : Fin p.size) : Prop :=
p[k] ≠ 0 ∧ (∀ j, (hj : j < p.size) → j > k → p[j] = 0)
def equiv (p q : UniPoly R) : Prop :=
∀ i, p.coeff i = q.coeff i
end Trim
def UniPolyC (R : Type*) [BEq R] [Ring R] := { p : UniPoly R // p.trim = p }
section Operations
variable {S : Type*}
def eval₂ [Semiring S] (f : R →+* S) (x : S) (p : UniPoly R) : S :=
p.zipIdx.foldl (fun acc ⟨a, i⟩ => acc + f a * x ^ i) 0
@[inline, specialize]
def add_raw (p q : UniPoly R) : UniPoly R :=
let ⟨p', q'⟩ := Array.matchSize p q 0
.mk (Array.zipWith (· + ·) p' q' )
variable (p q r : UniPoly R)
def canonical (p : UniPoly R) := p.trim = p
end Operations
namespace OperationsC
variable {R : Type*} [Ring R] [BEq R] [LawfulBEq R]
variable (p q r : UniPolyC R)
end OperationsC
section ToPoly
noncomputable def toPoly (p : UniPoly R) : Polynomial R :=
p.eval₂ Polynomial.C Polynomial.X
noncomputable def UniPolyC.toPoly (p : UniPolyC R) : Polynomial R := p.val.toPoly
alias ofPoly := Polynomial.toImpl | lemma toImpl_toPoly_of_canonical [LawfulBEq R] (p : UniPolyC R) : p.toPoly.toImpl = p := | := by
-- we will change something slightly more general: `toPoly` is injective on canonical polynomials
suffices h_inj : ∀ q : UniPolyC R, p.toPoly = q.toPoly → p = q by
have : p.toPoly = p.toPoly.toImpl.toPoly := by rw [toPoly_toImpl]
exact h_inj ⟨ p.toPoly.toImpl, trim_toImpl p.toPoly ⟩ this |> congrArg Subtype.val |>.symm
intro q hpq
apply UniPolyC.ext
apply Trim.canonical_ext p.property q.property
intro i
rw [← coeff_toPoly, ← coeff_toPoly]
exact hpq |> congrArg (fun p => p.coeff i) | 8 | 128 | false | Applied verif. |
43 | ConcreteBinaryTower.split_sum_eq_sum_split | theorem split_sum_eq_sum_split {k : ℕ} (h_pos : k > 0) (x₀ x₁ : ConcreteBTField k)
(hi₀ lo₀ hi₁ lo₁ : ConcreteBTField (k - 1))
(h_split_x₀ : split h_pos x₀ = (hi₀, lo₀))
(h_split_x₁ : split h_pos x₁ = (hi₁, lo₁)) :
split h_pos (x₀ + x₁) = (hi₀ + hi₁, lo₀ + lo₁) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "AlgebraTowerEquiv.symm",
"content": "def AlgebraTowerEquiv.symm (e : AlgebraTowerEquiv A B) : AlgebraTowerEquiv... | [
{
"name": "BitVec.ofNat_xor",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.xor_eq",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dcast (Eq.refl n) bv = bv"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
instance (k : ℕ) : HAdd (ConcreteBTField k) (ConcreteBTField k) (ConcreteBTField k) where
hAdd := add
instance (k : ℕ) : Add (ConcreteBTField k) where
add := add
-- split extracts the high and low halves of a bitvector using BitVec.extractLsb,
-- then casts them to the correct width using dcast. It returns (hi, lo).
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
have h_hi : 2 ^ k - 1 - 2 ^ (k - 1) + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
let lo : ConcreteBTField (k - 1) := dcast h_lo lo_bits
let hi : ConcreteBTField (k - 1) := dcast h_hi hi_bits
(hi, lo)
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k := | theorem split_sum_eq_sum_split {k : ℕ} (h_pos : k > 0) (x₀ x₁ : ConcreteBTField k)
(hi₀ lo₀ hi₁ lo₁ : ConcreteBTField (k - 1))
(h_split_x₀ : split h_pos x₀ = (hi₀, lo₀))
(h_split_x₁ : split h_pos x₁ = (hi₁, lo₁)) :
split h_pos (x₀ + x₁) = (hi₀ + hi₁, lo₀ + lo₁) := | := by
have h_x₀ := join_of_split h_pos x₀ hi₀ lo₀ h_split_x₀
have h_x₁ := join_of_split h_pos x₁ hi₁ lo₁ h_split_x₁
-- Approach : convert equation to Nat realm for simple proof
have h₀ := (split_bitvec_eq_iff_fromNat (k:=k) (h_pos:=h_pos) x₀ hi₀ lo₀).mp h_split_x₀
have h₁ := (split_bitvec_eq_iff_fromNat (k:=k) (h_pos:=h_pos) x₁ hi₁ lo₁).mp h_split_x₁
have h_sum_hi : (hi₀ + hi₁) = fromNat (BitVec.toNat (x₀ + x₁) >>> 2 ^ (k - 1)) := by
rw [h₀.1, h₁.1]
rw [←sum_fromNat_eq_from_xor_Nat]
have h_nat_eq : BitVec.toNat x₀ >>> 2 ^ (k - 1) ^^^ BitVec.toNat x₁ >>> 2 ^ (k - 1)
= BitVec.toNat (x₀ + x₁) >>> 2 ^ (k - 1) := by
-- unfold Concrete BTF addition into BitVec.xor
simp only [instHAddConcreteBTField, add, BitVec.xor_eq]
rw [Nat.shiftRight_xor_distrib.symm]
rw [BitVec.toNat_xor] -- distribution of BitVec.xor over BitVec.toNat
rw [h_nat_eq]
have h_sum_lo : (lo₀ + lo₁) = fromNat (BitVec.toNat (x₀ + x₁) &&& 2 ^ 2 ^ (k - 1) - 1) := by
rw [h₀.2, h₁.2]
rw [←sum_fromNat_eq_from_xor_Nat]
have h_nat_eq : BitVec.toNat x₀ &&& 2 ^ 2 ^ (k - 1) - 1 ^^^ BitVec.toNat x₁
&&& 2 ^ 2 ^ (k - 1) - 1 = BitVec.toNat (x₀ + x₁) &&& 2 ^ 2 ^ (k - 1) - 1 := by
simp only [instHAddConcreteBTField, add, BitVec.xor_eq]
rw [BitVec.toNat_xor]
rw [Nat.and_xor_distrib_right.symm]
rw [h_nat_eq]
have h_sum_hi_lo : (hi₀ + hi₁, lo₀ + lo₁) = split h_pos (x₀ + x₁) := by
rw [(split_bitvec_eq_iff_fromNat (k:=k) (h_pos:=h_pos) (x₀ + x₁)
(hi₀ + hi₁) (lo₀ + lo₁)).mpr ⟨h_sum_hi, h_sum_lo⟩]
exact h_sum_hi_lo.symm | 8 | 106 | false | Applied verif. |
44 | ConcreteBinaryTower.concrete_eq_zero_or_eq_one | theorem concrete_eq_zero_or_eq_one {k : ℕ} {a : ConcreteBTField k} (h_k_zero : k = 0)
: a = zero ∨ a = one | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "AlgebraTowerEquiv.symm",
"content": "def AlgebraTowerEquiv.symm (e : AlgebraTowerEquiv A B) : AlgebraTowerEquiv... | [
{
"name": "BitVec.cast_ofNat",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.ofNat_eq_ofNat",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.eq_zero_or_eq_one",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "congrArg",
"module": "Init.Prelude"
},
... | [
{
"name": "dcast_eq_root_cast",
"content": "theorem dcast_eq_root_cast (h : a = a') : dcast h b = _root_.cast (congrArg β h) b"
}
] | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.bitvec_cast_eq_dcast",
"content": "theorem BitVec.bitvec_cast_eq_dcast {n m : Nat} (h : n = m) (bv : BitVec n) :\n BitVec.cast h bv = DCast.dcast h bv"
},
{
"name": "ConcreteBinaryTower.BitVec.cast_one",
"content": "@[simp] theorem BitVec.cast_one {n m : ℕ}... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k) | theorem concrete_eq_zero_or_eq_one {k : ℕ} {a : ConcreteBTField k} (h_k_zero : k = 0)
: a = zero ∨ a = one := | := by
if h_k_zero : k = 0 then
have h_2_pow_k_eq_1 : 2 ^ k = 1 := by rw [h_k_zero]; norm_num
let a0 : ConcreteBTField 0 := Eq.mp (congrArg ConcreteBTField h_k_zero) a
have a0_is_eq_mp_a : a0 = Eq.mp (congrArg ConcreteBTField h_k_zero) a := by rfl
-- Approach : convert to BitVec.cast and derive equality of the cast for 0 and 1
rcases eq_zero_or_eq_one (a := a0) with (ha0 | ha1)
· -- a0 = zero
left
-- Transport equality back to ConcreteBTField k
have : a = Eq.mpr (congrArg ConcreteBTField h_k_zero) a0 := by
simp only [a0_is_eq_mp_a, eq_mp_eq_cast, eq_mpr_eq_cast, cast_cast, cast_eq]
rw [this, ha0]
-- zero (k:=k) = Eq.mpr ... (zero (k:=0))
have : zero = Eq.mpr (congrArg ConcreteBTField h_k_zero) (zero (k:=0)) := by
simp only [zero, eq_mpr_eq_cast, BitVec.zero]
rw [←dcast_eq_root_cast]
simp only [BitVec.ofNatLT_zero, Nat.pow_zero]
rw [BitVec.dcast_zero] -- ⊢ 1 = 2 ^ k
exact h_2_pow_k_eq_1.symm
rw [this]
· -- a0 = one
right
have : a = Eq.mpr (congrArg ConcreteBTField h_k_zero) a0 := by
simp only [a0_is_eq_mp_a, eq_mp_eq_cast, eq_mpr_eq_cast, cast_cast, cast_eq]
rw [this, ha1]
have : one = Eq.mpr (congrArg ConcreteBTField h_k_zero) (one (k:=0)) := by
simp only [one, eq_mpr_eq_cast]
rw [←dcast_eq_root_cast]
simp only [Nat.pow_zero]
rw [BitVec.dcast_one] -- ⊢ 1 = 2 ^ k
exact h_2_pow_k_eq_1.symm
rw [this]
else
contradiction | 4 | 32 | false | Applied verif. |
45 | ConcreteBinaryTower.concrete_mul_left_distrib0 | lemma concrete_mul_left_distrib0 (a b c : ConcreteBTField 0) :
concrete_mul a (b + c) = concrete_mul a b + concrete_mul a c | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "Al... | [
{
"name": "BitVec.xor_self",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.eq_zero_or_eq_one",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.xor_eq_zero_iff",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "if_neg",
"module": "Init.Core"
},
{
... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.add_self_cancel",
"content": "lemma add_self_cancel {k : ℕ} (a : ConcreteBTField k) : a + a = 0"
},
{
"name": "ConcreteBinaryTower.add_eq_zero_iff_eq",
"content": "lemma add_eq_zero_iff_eq {k : ℕ} (a b : ConcreteBTField k) : a + b = 0 ↔ a = b"
},
{
"name": ... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
section FieldLemmasOfLevel0 | lemma concrete_mul_left_distrib0 (a b c : ConcreteBTField 0) :
concrete_mul a (b + c) = concrete_mul a b + concrete_mul a c := | := by
rcases eq_zero_or_eq_one (a := a) with (ha | ha)
· simp [ha, concrete_mul, zero_is_0] -- a = zero
· simp [ha, concrete_mul, zero_is_0, one_is_1];
rcases eq_zero_or_eq_one (a := b + c) with (hb_add_c | hb_add_c)
· simp [hb_add_c, zero_is_0];
rw [zero_is_0] at hb_add_c
have b_eq_c : b = c := (add_eq_zero_iff_eq b c).mp hb_add_c
simp only [b_eq_c, add_self_cancel]
· simp [hb_add_c, one_is_1];
have c_cases := (add_eq_one_iff b c).mp hb_add_c
rcases eq_zero_or_eq_one (a := b) with (hb | hb)
· simp [hb, zero_is_0];
rw [one_is_1] at hb_add_c
rw [zero_is_0] at hb
simp [hb] at c_cases
have c_ne_0 : c ≠ 0 := by
simp only [c_cases, ne_eq, one_ne_zero, not_false_eq_true]
rw [if_neg c_ne_0]
exact c_cases.symm
· rw [one_is_1] at hb; simp [hb];
simp [hb] at c_cases
exact c_cases | 5 | 32 | false | Applied verif. |
46 | coeffs_of_comp_minus_x | theorem coeffs_of_comp_minus_x {f : Polynomial F} {n : ℕ} :
(f.comp (-X)).coeff n = if Even n then f.coeff n else -f.coeff n | ArkLib | ArkLib/Data/FieldTheory/NonBinaryField/Basic.lean | [
"import Mathlib.Tactic.FieldSimp",
"import Mathlib.Algebra.Polynomial.FieldDivision",
"import Mathlib.Tactic.LinearCombination"
] | [
{
"name": "Semiring",
"module": "Mathlib.Algebra.Ring.Defs"
},
{
"name": "Even",
"module": "Mathlib.Algebra.Group.Even"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Polynomial.X",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
... | [
{
"name": "coeff.{u}",
"content": "def coeff.{u} {F : Type u} [Semiring F] (f : F[X][Y]) (i j : ℕ) : F := (f.coeff j).coeff i"
}
] | [
{
"name": "Nat.even_add_one",
"module": "Mathlib.Algebra.Group.Nat.Even"
},
{
"name": "Nat.even_iff",
"module": "Mathlib.Algebra.Group.Nat.Even"
},
{
"name": "Polynomial.coeff_X",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Polynomial.degree_pos_induction_on",
... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [] | [
{
"name": "coeffs_of_comp_minus_x_pos_degree",
"content": "private lemma coeffs_of_comp_minus_x_pos_degree {f : Polynomial F} {n : ℕ} (h : 0 < f.degree) :\n (f.comp (-X)).coeff n = if Even n then f.coeff n else -f.coeff n"
}
] | import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.LinearCombination
section NonBinaryField
variable {F : Type*} [NonBinaryField F]
end NonBinaryField
section
variable {F : Type*} [Field F]
open Polynomial | theorem coeffs_of_comp_minus_x {f : Polynomial F} {n : ℕ} :
(f.comp (-X)).coeff n = if Even n then f.coeff n else -f.coeff n := | := by
by_cases hpos : 0 < f.degree
· rw [coeffs_of_comp_minus_x_pos_degree hpos]
· have : f.natDegree = 0 := by aesop (add simp natDegree_pos_iff_degree_pos.symm)
cases n <;> aesop (add simp natDegree_eq_zero) | 2 | 12 | false | Applied verif. |
47 | UniPoly.Trim.eq_degree_of_equiv | lemma eq_degree_of_equiv [LawfulBEq R] {p q : UniPoly R} : equiv p q → p.degree = q.degree | ArkLib | ArkLib/Data/UniPoly/Basic.lean | [
"import Mathlib.Algebra.Tropical.Basic",
"import ArkLib.Data.Array.Lemmas",
"import Mathlib.RingTheory.Polynomial.Basic"
] | [
{
"name": "inline",
"module": "Init.Core"
},
{
"name": "Array",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Option",
... | [
{
"name": "findIdxRev?",
"content": "def findIdxRev? (cond : α → Bool) (as : Array α) : Option (Fin as.size) :=\n find ⟨ as.size, Nat.lt_succ_self _ ⟩\nwhere\n find : Fin (as.size + 1) → Option (Fin as.size)\n | 0 => none\n | ⟨ i+1, h ⟩ =>\n if (cond as[i]) then\n some ⟨ i, Nat.lt_of_suc... | [
{
"name": "Nat.lt_succ_self",
"module": "Init.Prelude"
},
{
"name": "Bool.false_eq_true",
"module": "Init.Data.Bool"
},
{
"name": "bne_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "bne_self_eq_false",
"module": "Init.SimpLemmas"
},
{
"name": "ne_eq",
"mod... | [
{
"name": "findIdxRev?_eq_some",
"content": "theorem findIdxRev?_eq_some {cond} {as : Array α} (h : ∃ i, ∃ hi : i < as.size, cond as[i]) :\n ∃ k : Fin as.size, findIdxRev? cond as = some k"
},
{
"name": "findIdxRev?_eq_none",
"content": "theorem findIdxRev?_eq_none {cond} {as : Array α} (h : ∀ ... | [
{
"name": "UniPoly",
"content": "@[reducible, inline, specialize]\ndef UniPoly (R : Type*) := Array R"
},
{
"name": "UniPoly.coeff",
"content": "@[reducible]\ndef coeff (p : UniPoly Q) (i : ℕ) : Q := p.getD i 0"
},
{
"name": "UniPoly.last_nonzero",
"content": "def last_nonzero (p : U... | [
{
"name": "UniPoly.Trim.last_nonzero_none",
"content": "theorem last_nonzero_none [LawfulBEq R] {p : UniPoly R} :\n (∀ i, (hi : i < p.size) → p[i] = 0) → p.last_nonzero = none"
},
{
"name": "UniPoly.Trim.last_nonzero_some",
"content": "theorem last_nonzero_some [LawfulBEq R] {p : UniPoly R} {i}... | import Mathlib.Algebra.Tropical.Basic
import Mathlib.RingTheory.Polynomial.Basic
import ArkLib.Data.Array.Lemmas
open Polynomial
@[reducible, inline, specialize]
def UniPoly (R : Type*) := Array R
namespace UniPoly
variable {R : Type*} [Ring R] [BEq R]
variable {Q : Type*} [Ring Q]
@[reducible]
def coeff (p : UniPoly Q) (i : ℕ) : Q := p.getD i 0
def last_nonzero (p : UniPoly R) : Option (Fin p.size) :=
p.findIdxRev? (· != 0)
def degree (p : UniPoly R) : Nat :=
match p.last_nonzero with
| none => 0
| some i => i.val + 1
namespace Trim
def last_nonzero_prop {p : UniPoly R} (k : Fin p.size) : Prop :=
p[k] ≠ 0 ∧ (∀ j, (hj : j < p.size) → j > k → p[j] = 0)
def equiv (p q : UniPoly R) : Prop :=
∀ i, p.coeff i = q.coeff i | lemma eq_degree_of_equiv [LawfulBEq R] {p q : UniPoly R} : equiv p q → p.degree = q.degree := | := by
unfold equiv degree
intro h_equiv
induction p using last_nonzero_induct with
| case1 p h_none_p h_all_zero =>
have h_zero_p : ∀ i, p.coeff i = 0 := coeff_eq_zero.mp h_all_zero
have h_zero_q : ∀ i, q.coeff i = 0 := by intro i; rw [← h_equiv, h_zero_p]
have h_none_q : q.last_nonzero = none := last_nonzero_none (coeff_eq_zero.mpr h_zero_q)
rw [h_none_p, h_none_q]
| case2 p k h_some_p h_nonzero_p h_max_p =>
have h_equiv_k := h_equiv k
have k_lt_q : k < q.size := by
by_contra h_not_lt
have h_ge := Nat.le_of_not_lt h_not_lt
simp [h_ge] at h_equiv_k
contradiction
simp [k_lt_q] at h_equiv_k
have h_nonzero_q : q[k.val] ≠ 0 := by rwa [← h_equiv_k]
have h_max_q : ∀ j, (hj : j < q.size) → j > k → q[j] = 0 := by
intro j hj j_gt_k
have h_eq := h_equiv j
simp [hj] at h_eq
rw [← h_eq]
rcases Nat.lt_or_ge j p.size with hj | hj
· simp [hj, h_max_p j hj j_gt_k]
· simp [hj]
have h_some_q : q.last_nonzero = some ⟨ k, k_lt_q ⟩ :=
last_nonzero_some_iff.mpr ⟨ h_nonzero_q, h_max_q ⟩
rw [h_some_p, h_some_q] | 3 | 36 | false | Applied verif. |
48 | ConcreteBinaryTower.towerRingHomForwardMap_Z | lemma towerRingHomForwardMap_Z (k : ℕ) :
towerRingHomForwardMap k (Z k) = BinaryTower.Z k | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "BT... | [
{
"name": "BitVec.extractLsb_ofNat",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.zero_eq",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "Nat.shiftRight_zero",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Bas... | [
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "join_via_add_smul_zero",
"content": "lemma join_via_add_smul_zero {k : ℕ} (h_pos : k > 0) :\n ⋘ 0, 0 ⋙ = 0"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dcast (Eq.refl n) bv = bv"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_bitvec_eq",
"content": "theorem BitVec.dcast_bitvec_eq {l r val : ℕ} (h_width_eq : l = r) :\n dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
end NumericCasting
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
end ConcreteBTFieldAlgebraConstruction
noncomputable section ConcreteMultilinearBasis
open Module
end ConcreteMultilinearBasis
section TowerEquivalence
open BinaryTower
noncomputable def towerRingEquivFromConcrete0 : ConcreteBTField 0 ≃+* BTField 0 :=
noncomputable def towerRingHomForwardMap (k : ℕ) : ConcreteBTField k → BTField k := | lemma towerRingHomForwardMap_Z (k : ℕ) :
towerRingHomForwardMap k (Z k) = BinaryTower.Z k := | := by
induction k with
| zero =>
unfold towerRingHomForwardMap
simp only [RingEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe, ↓reduceDIte,
towerRingEquivFromConcrete0]
rfl
| succ k ih =>
unfold towerRingHomForwardMap
simp only [Nat.add_eq_zero, one_ne_zero, and_false, ↓reduceDIte,
Nat.add_one_sub_one]
rw! [split_Z]
simp only [Nat.add_one_sub_one, one_is_1, zero_is_0]
rw! [towerRingHomForwardMap_zero, towerRingHomForwardMap_one]
exact BinaryTower.join_via_add_smul_one_zero_eq_Z (k:=k+1) (h_pos:=by omega) | 9 | 196 | false | Applied verif. |
49 | Nat.num_eq_highBits_add_lowBits | lemma num_eq_highBits_add_lowBits {n: ℕ} (numLowBits: ℕ) :
n = getHighBits numLowBits n + getLowBits numLowBits n | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Nat.and_distrib_right",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.testBit",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Nat.binaryRec",... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.shiftRight_add",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "add_comm",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Nat.and_one_is_mod",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.eq_of_testBit_eq",
"module": "Init.Data.Na... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "Nat.getLowBits",
"content": "def getLowBits (numLowBits : ℕ) (n : ℕ) := n &&& ((1 <<< numLowBits) - 1)"
},
{
"name": "Nat.getHighBits_no_shl",
"content": "def getHighBits_no_shl (numLow... | [
{
"name": "Nat.getBit_lt_2",
"content": "lemma getBit_lt_2 {k n : Nat} : getBit k n < 2"
},
{
"name": "Nat.eq_iff_eq_all_getBits",
"content": "lemma eq_iff_eq_all_getBits {n m : ℕ} : n = m ↔ ∀ k, getBit k n = getBit k m"
},
{
"name": "Nat.shiftRight_and_one_distrib",
"content": "lemm... | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1
def getLowBits (numLowBits : ℕ) (n : ℕ) := n &&& ((1 <<< numLowBits) - 1)
def getHighBits_no_shl (numLowBits : ℕ) (n : ℕ) : ℕ := n >>> numLowBits
def getHighBits (numLowBits : ℕ) (n : ℕ) : ℕ :=
(getHighBits_no_shl numLowBits n) <<< numLowBits | lemma num_eq_highBits_add_lowBits {n: ℕ} (numLowBits: ℕ) :
n = getHighBits numLowBits n + getLowBits numLowBits n := | := by
apply eq_iff_eq_all_getBits.mpr; unfold getBit
intro k
--- use 2 getBit extractions to get the condition for getLowBits of ((n >>> numLowBits) <<<
-- numLowBits)
set highBits_no_shl := n >>> numLowBits
have h_getBit_highBits_shl := getBit_of_shiftLeft (n := highBits_no_shl) (p := numLowBits)
have h_getBit_lowBits := getBit_of_lowBits (n := n) (numLowBits := numLowBits)
-- AND of highBitss & lowBitss is 0 => we use this to convert the sum into OR
have h_and := and_highBits_lowBits_eq_zero (n := n) (numLowBits := numLowBits)
rw [sum_of_and_eq_zero_is_or h_and]
--- now reason on bitwise operations only
rw [Nat.shiftRight_or_distrib, Nat.and_distrib_right]
change getBit k n = getBit k ((n >>> numLowBits) <<< numLowBits)
||| getBit k (getLowBits numLowBits n)
rw [h_getBit_highBits_shl, h_getBit_lowBits]
if h_k: k < numLowBits then
simp only [h_k, ↓reduceIte, Nat.zero_or] at *
else
have h_ne: ¬(k < numLowBits) := by omega
have h_num_le_k: numLowBits ≤ k := by omega
simp only [h_ne, not_false_eq_true, ↓reduceIte, Nat.or_zero] at *
rw [getBit_of_shiftRight]
congr
rw [Nat.sub_add_cancel (n:=k) (m:=numLowBits) (by omega)] | 4 | 103 | false | Applied verif. |
50 | BerlekampWelch.elocPolyF_deg | @[simp]
lemma elocPolyF_deg {ωs f : Fin n → F} : (ElocPolyF ωs f p).natDegree = Δ₀(f, p.eval ∘ ωs) | ArkLib | ArkLib/Data/CodingTheory/BerlekampWelch/ElocPoly.lean | [
"import ArkLib.Data.CodingTheory.Basic",
"import Init.Data.List.FinRange",
"import ArkLib.Data.Fin.Lift",
"import Mathlib.Data.Finset.Insert",
"import Mathlib.Data.Fintype.Card",
"import Mathlib.Algebra.Polynomial.FieldDivision",
"import Mathlib.Data.Matrix.Mul",
"import Mathlib.Algebra.Field.Basic",
... | [
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.prod",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.range",
"module": "Init.Data.List.Basic"
},
{
"name": "Polynomial.... | [
{
"name": "hammingDist",
"content": "notation \"Δ₀(\" u \", \" v \")\" => hammingDist u v"
},
{
"name": "distFromCode",
"content": "notation \"Δ₀(\" u \", \" C \")\" => distFromCode u C"
},
{
"name": "scoped macro_rules",
"content": "scoped macro_rules\n | `(ρ $t:term) => `(LinearCo... | [
{
"name": "List.mem_range",
"module": "Init.Data.List.Nat.Range"
},
{
"name": "List.pmap_eq_map",
"module": "Init.Data.List.Attach"
},
{
"name": "List.pmap_eq_map_attach",
"module": "Init.Data.List.Attach"
},
{
"name": "Polynomial.ext",
"module": "Mathlib.Algebra.Polynomi... | [
{
"name": "contract_eq_liftF_of_lt",
"content": "lemma contract_eq_liftF_of_lt {k : ℕ} (h₁ : k < m) :\n contract m f' k = liftF f' k"
},
{
"name": "liftF_succ",
"content": "@[simp]\nlemma liftF_succ {f : Fin (n + 1) → α} : liftF f n = f ⟨n, Nat.lt_add_one _⟩"
}
] | [
{
"name": "BerlekampWelch.ElocPoly",
"content": "protected noncomputable def ElocPoly (n : ℕ) (ωs f : ℕ → F) (p : Polynomial F) : Polynomial F :=\n List.prod <| (List.range n).map fun i =>\n if f i = p.eval (ωs i)\n then 1\n else X - C (ωs i)"
},
{
"name": "BerlekampWelch.ElocPolyF",
"... | [
{
"name": "BerlekampWelch.elocPoly_zero",
"content": "@[simp]\nprotected lemma elocPoly_zero : ElocPoly 0 ωs f p = 1"
},
{
"name": "BerlekampWelch.elocPoly_succ",
"content": "@[simp]\nprotected lemma elocPoly_succ :\n ElocPoly (n + 1) ωs f p =\n ElocPoly n ωs f p *\n if f n = p.eval (ωs n)\... | import Init.Data.List.FinRange
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.Data.Finset.Insert
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Matrix.Mul
import ArkLib.Data.CodingTheory.Basic
import ArkLib.Data.Fin.Lift
namespace BerlekampWelch
variable {F : Type} [Field F]
{m n : ℕ} {p : Polynomial F}
variable [DecidableEq F]
section ElocPoly
open Polynomial
protected noncomputable def ElocPoly (n : ℕ) (ωs f : ℕ → F) (p : Polynomial F) : Polynomial F :=
List.prod <| (List.range n).map fun i =>
if f i = p.eval (ωs i)
then 1
else X - C (ωs i)
section
open BerlekampWelch (ElocPoly)
variable {ωs f : ℕ → F}
open BerlekampWelch (elocPoly_succ) in
section
open Fin
open BerlekampWelch (elocPoly_congr)
noncomputable def ElocPolyF (ωs f : Fin n → F) (p : Polynomial F) : Polynomial F :=
ElocPoly n (liftF ωs) (liftF f) p
open BerlekampWelch
(elocPolyF_eq_elocPoly' elocPoly_leftF_leftF_eq_contract
elocPoly_zero elocPoly_succ)
open Fin | @[simp]
lemma elocPolyF_deg {ωs f : Fin n → F} : (ElocPolyF ωs f p).natDegree = Δ₀(f, p.eval ∘ ωs) := | := by
rw [elocPolyF_eq_elocPoly']
induction' n with n ih
· simp only [elocPoly_zero, natDegree_one, hamming_zero_eq_dist]
exact funext_iff.2 (Fin.elim0 ·)
· rw [
elocPoly_succ,
natDegree_mul (by simp)
(by aesop (erase simp liftF_succ)
(add simp [sub_eq_zero])
(add safe forward (X_ne_C (liftF ωs n)))),
elocPoly_leftF_leftF_eq_contract
]
aesop (config := {warnOnNonterminal := false}) (add simp [
hammingDist.eq_def, Finset.card_filter, Finset.sum_fin_eq_sum_range, Finset.sum_range_succ
]) <;> (apply Finset.sum_congr rfl; aesop (add safe (by omega))) | 4 | 42 | false | Applied verif. |
51 | Fin.zero_dappend | @[simp]
theorem zero_dappend {motive : Fin (0 + n) → Sort u} {u : (i : Fin 0) → motive (castAdd n i)}
(v : (i : Fin n) → motive (natAdd 0 i)) :
dappend (motive := motive) u v = fun i => cast (by simp) (v (i.cast (by omega))) | ArkLib | ArkLib/Data/Fin/Tuple/Lemmas.lean | [
"import ArkLib.Data.Fin.Tuple.Notation"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin.last",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Fin.castAdd",
"module": "Init.Data.Fin.Basic"... | [
{
"name": "dappend",
"content": "@[elab_as_elim]\ndef dappend {m n : ℕ} {motive : Fin (m + n) → Sort u}\n (u : (i : Fin m) → motive (Fin.castAdd n i))\n (v : (i : Fin n) → motive (Fin.natAdd m i))\n (i : Fin (m + n)) : motive i :=\n match n with\n | 0 => u i\n | k + 1 => dconcat (dappend u (fun ... | [
{
"name": "Fin.ext",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.snoc_castSucc",
"module": "Mathlib.Data.Fin.Tuple.Basic"
},
{
"name": "Fin.snoc_last",
"module": "Mathlib.Data.Fin.Tuple.Basic"
},
{
"name": "Fin.forall_fin_zero_pi",
"module": "Mathlib.Data.Fin.Tuple... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [] | [
{
"name": "Fin.dconcat_last",
"content": "@[simp]\ntheorem dconcat_last {motive : Fin (n + 1) → Sort u} (v : (i : Fin n) → motive (castSucc i))\n (a : motive (last n)) : (v :+ᵈ⟨motive⟩ a) (last n) = a"
},
{
"name": "Fin.dconcat_castSucc",
"content": "@[simp]\ntheorem dconcat_castSucc {motive ... | import ArkLib.Data.Fin.Tuple.Notation
namespace Fin
variable {m n : ℕ} {α : Sort u} | @[simp]
theorem zero_dappend {motive : Fin (0 + n) → Sort u} {u : (i : Fin 0) → motive (castAdd n i)}
(v : (i : Fin n) → motive (natAdd 0 i)) :
dappend (motive := motive) u v = fun i => cast (by simp) (v (i.cast (by omega))) := | := by
induction n with
| zero => ext i; exact Fin.elim0 i
| succ n ih =>
simp [dappend, ih, dconcat_eq_snoc, Fin.cast, last]
ext i
by_cases h : i.val < n
· have : i = Fin.castSucc ⟨i.val, by simp [h]⟩ := by ext; simp
rw [this, snoc_castSucc]
simp
· have : i.val = n := by omega
have : i = Fin.last _ := by ext; simp [this]
rw! [this]
subst this
simp_all only [forall_fin_zero_pi, Nat.add_eq, val_last, zero_add,
lt_self_iff_false, not_false_eq_true, snoc_last]
grind only [cases Or] | 5 | 27 | false | Applied verif. |
52 | BerlekampWelch.solutionToQ_zero | @[simp]
lemma solutionToQ_zero {v : Fin (2 * 0 + 0) → F} :
solutionToQ (F := F) 0 0 v = 0 := rfl | ArkLib | ArkLib/Data/CodingTheory/BerlekampWelch/Condition.lean | [
"import Mathlib.Data.Matrix.Reflection",
"import ArkLib.Data.CodingTheory.Basic",
"import ArkLib.Data.CodingTheory.BerlekampWelch.Sorries",
"import Init.Data.List.FinRange",
"import Mathlib.Data.Finset.Insert",
"import ArkLib.Data.Polynomial.Interface",
"import Mathlib.Data.Fintype.Card",
"import Math... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Polynomial",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.add",
"module": "Mathlib.Algebra.Group.Pointwise.Finset.Basic"
},
{
"... | [
{
"name": "liftF",
"content": "def liftF (f : Fin n → α) : ℕ → α :=\n fun m ↦ if h : m < n then f ⟨m, h⟩ else 0"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "BerlekampWelch.solutionToQ",
"content": "def solutionToQ (e k : ℕ) (v : Fin (2 * e + k) → F) : Polynomial F :=\n ⟨\n (Finset.range (e + k)).filter (fun x => liftF v (e + x) ≠ 0),\n fun i => if i < e + k then liftF v (e + i) else 0,\n by admit /- proof elided -/\n ⟩"
}
] | [] | import Init.Data.List.FinRange
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.Data.Finset.Insert
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Matrix.Mul
import Mathlib.Data.Matrix.Reflection
import ArkLib.Data.CodingTheory.Basic
import ArkLib.Data.Polynomial.Interface
import ArkLib.Data.CodingTheory.BerlekampWelch.ElocPoly
import ArkLib.Data.CodingTheory.BerlekampWelch.Sorries
namespace BerlekampWelch
variable {α : Type} {F : Type} [Field F]
{n e k : ℕ}
{i : Fin n}
{j : Fin (2 * e + k)}
{ωs f : Fin n → F}
{v : Fin (2 * e + k) → F}
{E Q : Polynomial F}
{p : Polynomial F}
section
open Polynomial Finset in
open Fin
open Polynomial
variable [DecidableEq F]
def solutionToQ (e k : ℕ) (v : Fin (2 * e + k) → F) : Polynomial F :=
⟨
(Finset.range (e + k)).filter (fun x => liftF v (e + x) ≠ 0),
fun i => if i < e + k then liftF v (e + i) else 0,
by admit /- proof elided -/
⟩ | @[simp]
lemma solutionToQ_zero {v : Fin (2 * 0 + 0) → F} :
solutionToQ (F := F) 0 0 v = 0 := | := rfl | 2 | 6 | false | Applied verif. |
53 | BinaryTower.eq_join_via_add_smul_eq_iff_split | theorem eq_join_via_add_smul_eq_iff_split (k : ℕ) (h_pos : k > 0)
(x : BTField k) (hi_btf lo_btf : BTField (k - 1)) :
x = ⋘ hi_btf, lo_btf ⋙ ↔
split (k:=k) (h_k:=h_pos) x = (hi_btf, lo_btf) | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Basic.lean | [
"import Mathlib.Tactic.DepRewrite",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.RingTheory.AlgebraTower"
] | [
{
"name": "Field",
"module": "Mathlib.Algebra.Field.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.range",
"module": "Mathlib.Data.Finset.Range"
},
{
"name": "Polynomial.C",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "TraceMapProperty",
"content": "structure TraceMapProperty (F : Type*) [Field F] (u : F) (k : ℕ) : Prop where\n element_trace : ∑ i ∈ Finset.range (2 ^ k), u ^ (2 ^ i) = 1\n inverse_t... | [
{
"name": "Ne.dite_eq_left_iff",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.add_one_sub_one",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.left_eq_add",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "RingHom.comp_id",
"module": "Mathlib.Algebra.Ring.Hom.Defs"
... | [
{
"name": "degree_definingPoly",
"content": "lemma degree_definingPoly {F : Type*} [Field F] [Fintype F] (s : F) [NeZero s] :\n (definingPoly s).degree = 2"
},
{
"name": "degree_s_smul_X_add_1",
"content": "lemma degree_s_smul_X_add_1 {F : Type*} [Field F] [Fintype F] (s : F) [NeZero s] :\n (C... | [
{
"name": "BinaryTower.BinaryTowerResult",
"content": "structure BinaryTowerResult (F : Type _) (k : ℕ) where\n vec : (List.Vector F (k + 1))\n instField : (Field F)\n instFintype : Fintype F\n specialElement : F\n specialElementNeZero : NeZero specialElement\n firstElementOfVecIsSpecialElement [Inhab... | [
{
"name": "BinaryTower.poly_natDegree_eq_2",
"content": "lemma poly_natDegree_eq_2 (k : ℕ) : (poly (k:=k)).natDegree = 2"
},
{
"name": "BinaryTower.BTField.cast_BTField_eq",
"content": "lemma BTField.cast_BTField_eq (k m : ℕ) (h_eq : k = m) :\n BTField k = BTField m"
},
{
"name": "Binar... | import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude
import ArkLib.Data.RingTheory.AlgebraTower
import Mathlib.Tactic.DepRewrite
namespace BinaryTower
noncomputable section
open Polynomial AdjoinRoot Module
section BTFieldDefs
structure BinaryTowerResult (F : Type _) (k : ℕ) where
vec : (List.Vector F (k + 1))
instField : (Field F)
instFintype : Fintype F
specialElement : F
specialElementNeZero : NeZero specialElement
firstElementOfVecIsSpecialElement [Inhabited F] : vec.1.headI = specialElement
instIrreduciblePoly : (Irreducible (p := (definingPoly specialElement)))
sumZeroIffEq : ∀ (x y : F), x + y = 0 ↔ x = y
fieldFintypeCard : Fintype.card F = 2^(2^k)
traceMapEvalAtRootsIs1 : TraceMapProperty F specialElement k
structure BinaryTowerInductiveStepResult (k : ℕ) (prevBTField : Type _)
(prevBTResult : BinaryTowerResult prevBTField k) [instPrevBTFieldIsField : Field prevBTField]
(prevPoly : Polynomial prevBTField) (F : Type _) where
binaryTowerResult : BinaryTowerResult F (k+1)
eq_adjoin : F = AdjoinRoot prevPoly
u_is_root : Eq.mp (eq_adjoin) binaryTowerResult.specialElement = AdjoinRoot.root prevPoly
eval_defining_poly_at_root : Eq.mp (eq_adjoin) binaryTowerResult.specialElement^2 +
Eq.mp (eq_adjoin) binaryTowerResult.specialElement * (of prevPoly) prevBTResult.specialElement
+ 1 = 0
def binary_tower_inductive_step
(k : Nat)
(prevBTField : Type _) [Field prevBTField]
(prevBTResult : BinaryTowerResult prevBTField k)
: Σ' (F : Type _), BinaryTowerInductiveStepResult (k:=k) (prevBTField:=prevBTField)
(prevBTResult:=prevBTResult) (prevPoly:=definingPoly (F:=prevBTField)
(instField:=prevBTResult.instField) (s:=prevBTResult.specialElement)) (F:=F)
(instPrevBTFieldIsField:=prevBTResult.instField) :=
def BinaryTowerAux (k : ℕ) : (Σ' (F : Type 0), BinaryTowerResult F k) :=
match k with
| 0 =>
let curBTField := GF(2)
let newList : List.Vector (GF(2)) 1 := List.Vector.cons (1 : GF(2)) List.Vector.nil
let specialElement : GF(2) := newList.1.headI
let firstElementOfVecIsSpecialElement : newList.1.headI = specialElement := rfl
let specialElementIs1 : specialElement = 1 := by admit /- proof elided -/
@[simp]
def BTField (k : ℕ) := (BinaryTowerAux k).1
@[simp]
instance Inhabited (k : ℕ) : Inhabited (BTField k) where
default := (0 : BTField k)
@[simp]
def sumZeroIffEq (k : ℕ) : ∀ (x y : BTField k),
x + y = 0 ↔ x = y := (BinaryTowerAux k).2.sumZeroIffEq
@[simp]
def Z (k : ℕ) : BTField k := (BinaryTowerAux k).snd.specialElement
@[simp]
def poly (k : ℕ) : Polynomial (BTField k) := definingPoly (s:=(Z k))
instance polyMonic (n : ℕ) : Monic (poly n) := definingPoly_is_monic (Z n)
end BTFieldDefs
section BinaryAlgebraTower
def canonicalEmbedding (k : ℕ) : BTField k →+* BTField (k+1) :=
AdjoinRoot.of (poly k)
def towerAlgebraMap (l r : ℕ) (h_le : l ≤ r) : BTField l →+* BTField r :=
def binaryAlgebraTower {l r : ℕ} (h_le : l ≤ r) : Algebra (BTField l) (BTField r) :=
instance (priority := 1000) algebra_adjacent_tower (l : ℕ) :
Algebra (BTField l) (BTField (l+1)) :=
end BinaryAlgebraTower
noncomputable section MultilinearBasis
def join_via_add_smul {k : ℕ} (h_pos : k > 0) (hi_btf lo_btf : BTField (k - 1)) :
BTField k :=
def split (k : ℕ) (h_k : k > 0) (x : BTField k) : BTField (k-1) × BTField (k-1) := | theorem eq_join_via_add_smul_eq_iff_split (k : ℕ) (h_pos : k > 0)
(x : BTField k) (hi_btf lo_btf : BTField (k - 1)) :
x = ⋘ hi_btf, lo_btf ⋙ ↔
split (k:=k) (h_k:=h_pos) x = (hi_btf, lo_btf) := | := by
have h_k_sub_1_add_1_eq_k : k - 1 + 1 = k := by omega
have h_BTField_eq := BTField.cast_BTField_eq (k:=k) (m:=k-1+1) (h_eq:=by omega)
set p := unique_linear_decomposition_succ (k:=(k-1)) (x:=(Eq.mp (h:=h_BTField_eq) x)) with hp
-- -- ⊢ x = join_via_add_smul k h_pos hi lo
have h_p_satisfy := p.choose_spec
set xPair := p.choose
constructor
· intro h_x_eq_join
-- Due to `unique_linear_decomposition_succ`, there must be exactly one pair
-- `(hi, lo)` that satisfies the equation : `x = join_via_add_smul k h_pos hi lo`
-- Now we prove `⟨hi_btf, lo_btf⟩` is `Exists.choose` of `unique_linear_decomposition_succ`
-- which is actually same as the definition of the `split` function
have h_must_eq := h_p_satisfy.2 (⟨hi_btf, lo_btf⟩)
simp only [eq_mp_eq_cast] at h_must_eq
have h_hibtf_lobtf_eq_xPair := h_must_eq (by
rw! (castMode := .all) [h_k_sub_1_add_1_eq_k]
simp only [cast_eq]
convert h_x_eq_join
· rw [eqRec_eq_cast]; rfl
· rw [eqRec_eq_cast]; rfl
)
have h_split_eq_xPair : split k h_pos x = xPair := by rfl
rw [h_split_eq_xPair, h_hibtf_lobtf_eq_xPair.symm]
· intro h_split_eq
unfold split at h_split_eq
have h_hibtf_lobtf_eq_xPair : ⟨hi_btf, lo_btf⟩ = xPair := by rw [←h_split_eq]
have h_xPair_satisfy_join_via_add_smul := h_p_satisfy.1
rw [←h_hibtf_lobtf_eq_xPair] at h_xPair_satisfy_join_via_add_smul
rw [eq_mp_eq_cast] at h_xPair_satisfy_join_via_add_smul
rw! (castMode := .all) [h_k_sub_1_add_1_eq_k] at h_xPair_satisfy_join_via_add_smul
simp only [cast_eq] at h_xPair_satisfy_join_via_add_smul
convert h_xPair_satisfy_join_via_add_smul
· rw [eqRec_eq_cast]; rfl
· rw [eqRec_eq_cast]; rfl | 6 | 98 | false | Applied verif. |
54 | BinaryTower.algebraMap_eq_zero_x | lemma algebraMap_eq_zero_x {i j : ℕ} (h_le : i < j) (x : BTField i) :
letI instAlgebra := binaryAlgebraTower (l:=i) (r:=j) (h_le:=by omega)
letI instAlgebraPred := binaryAlgebraTower (l:=i) (r:=j-1) (h_le:=by omega)
algebraMap (BTField i) (BTField j) x
= ⋘ 0, algebraMap (BTField i) (BTField (j-1)) x ⋙ | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Basic.lean | [
"import Mathlib.Tactic.DepRewrite",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.RingTheory.AlgebraTower"
] | [
{
"name": "Field",
"module": "Mathlib.Algebra.Field.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.range",
"module": "Mathlib.Data.Finset.Range"
},
{
"name": "Polynomial.C",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "TraceMapProperty",
"content": "structure TraceMapProperty (F : Type*) [Field F] (u : F) (k : ℕ) : Prop where\n element_trace : ∑ i ∈ Finset.range (2 ^ k), u ^ (2 ^ i) = 1\n inverse_t... | [
{
"name": "Ne.dite_eq_left_iff",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.add_one_sub_one",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.left_eq_add",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "RingHom.comp_id",
"module": "Mathlib.Algebra.Ring.Hom.Defs"
... | [
{
"name": "degree_definingPoly",
"content": "lemma degree_definingPoly {F : Type*} [Field F] [Fintype F] (s : F) [NeZero s] :\n (definingPoly s).degree = 2"
},
{
"name": "degree_s_smul_X_add_1",
"content": "lemma degree_s_smul_X_add_1 {F : Type*} [Field F] [Fintype F] (s : F) [NeZero s] :\n (C... | [
{
"name": "BinaryTower.BinaryTowerResult",
"content": "structure BinaryTowerResult (F : Type _) (k : ℕ) where\n vec : (List.Vector F (k + 1))\n instField : (Field F)\n instFintype : Fintype F\n specialElement : F\n specialElementNeZero : NeZero specialElement\n firstElementOfVecIsSpecialElement [Inhab... | [
{
"name": "BinaryTower.poly_natDegree_eq_2",
"content": "lemma poly_natDegree_eq_2 (k : ℕ) : (poly (k:=k)).natDegree = 2"
},
{
"name": "BinaryTower.BTField.cast_BTField_eq",
"content": "lemma BTField.cast_BTField_eq (k m : ℕ) (h_eq : k = m) :\n BTField k = BTField m"
},
{
"name": "Binar... | import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude
import ArkLib.Data.RingTheory.AlgebraTower
import Mathlib.Tactic.DepRewrite
namespace BinaryTower
noncomputable section
open Polynomial AdjoinRoot Module
section BTFieldDefs
structure BinaryTowerResult (F : Type _) (k : ℕ) where
vec : (List.Vector F (k + 1))
instField : (Field F)
instFintype : Fintype F
specialElement : F
specialElementNeZero : NeZero specialElement
firstElementOfVecIsSpecialElement [Inhabited F] : vec.1.headI = specialElement
instIrreduciblePoly : (Irreducible (p := (definingPoly specialElement)))
sumZeroIffEq : ∀ (x y : F), x + y = 0 ↔ x = y
fieldFintypeCard : Fintype.card F = 2^(2^k)
traceMapEvalAtRootsIs1 : TraceMapProperty F specialElement k
structure BinaryTowerInductiveStepResult (k : ℕ) (prevBTField : Type _)
(prevBTResult : BinaryTowerResult prevBTField k) [instPrevBTFieldIsField : Field prevBTField]
(prevPoly : Polynomial prevBTField) (F : Type _) where
binaryTowerResult : BinaryTowerResult F (k+1)
eq_adjoin : F = AdjoinRoot prevPoly
u_is_root : Eq.mp (eq_adjoin) binaryTowerResult.specialElement = AdjoinRoot.root prevPoly
eval_defining_poly_at_root : Eq.mp (eq_adjoin) binaryTowerResult.specialElement^2 +
Eq.mp (eq_adjoin) binaryTowerResult.specialElement * (of prevPoly) prevBTResult.specialElement
+ 1 = 0
def binary_tower_inductive_step
(k : Nat)
(prevBTField : Type _) [Field prevBTField]
(prevBTResult : BinaryTowerResult prevBTField k)
: Σ' (F : Type _), BinaryTowerInductiveStepResult (k:=k) (prevBTField:=prevBTField)
(prevBTResult:=prevBTResult) (prevPoly:=definingPoly (F:=prevBTField)
(instField:=prevBTResult.instField) (s:=prevBTResult.specialElement)) (F:=F)
(instPrevBTFieldIsField:=prevBTResult.instField) :=
def BinaryTowerAux (k : ℕ) : (Σ' (F : Type 0), BinaryTowerResult F k) :=
match k with
| 0 =>
let curBTField := GF(2)
let newList : List.Vector (GF(2)) 1 := List.Vector.cons (1 : GF(2)) List.Vector.nil
let specialElement : GF(2) := newList.1.headI
let firstElementOfVecIsSpecialElement : newList.1.headI = specialElement := rfl
let specialElementIs1 : specialElement = 1 := by admit /- proof elided -/
@[simp]
def BTField (k : ℕ) := (BinaryTowerAux k).1
@[simp]
instance Inhabited (k : ℕ) : Inhabited (BTField k) where
default := (0 : BTField k)
@[simp]
def sumZeroIffEq (k : ℕ) : ∀ (x y : BTField k),
x + y = 0 ↔ x = y := (BinaryTowerAux k).2.sumZeroIffEq
@[simp]
def Z (k : ℕ) : BTField k := (BinaryTowerAux k).snd.specialElement
@[simp]
def poly (k : ℕ) : Polynomial (BTField k) := definingPoly (s:=(Z k))
instance polyMonic (n : ℕ) : Monic (poly n) := definingPoly_is_monic (Z n)
end BTFieldDefs
section BinaryAlgebraTower
def canonicalEmbedding (k : ℕ) : BTField k →+* BTField (k+1) :=
AdjoinRoot.of (poly k)
def towerAlgebraMap (l r : ℕ) (h_le : l ≤ r) : BTField l →+* BTField r :=
def binaryAlgebraTower {l r : ℕ} (h_le : l ≤ r) : Algebra (BTField l) (BTField r) :=
instance (priority := 1000) algebra_adjacent_tower (l : ℕ) :
Algebra (BTField l) (BTField (l+1)) :=
end BinaryAlgebraTower
noncomputable section MultilinearBasis
def join_via_add_smul {k : ℕ} (h_pos : k > 0) (hi_btf lo_btf : BTField (k - 1)) :
BTField k :=
def split (k : ℕ) (h_k : k > 0) (x : BTField k) : BTField (k-1) × BTField (k-1) := | lemma algebraMap_eq_zero_x {i j : ℕ} (h_le : i < j) (x : BTField i) :
letI instAlgebra := | := binaryAlgebraTower (l:=i) (r:=j) (h_le:=by omega)
letI instAlgebraPred := binaryAlgebraTower (l:=i) (r:=j-1) (h_le:=by omega)
algebraMap (BTField i) (BTField j) x
= ⋘ 0, algebraMap (BTField i) (BTField (j-1)) x ⋙ := by
set d := j - i with d_eq
induction hd : d with
| zero =>
have h_i_eq_j : i = j := by omega
have h_i_ne_j : i ≠ j := by omega
contradiction
| succ d' => -- this one does not even use inductive hypothesis
have h_j_eq : j = i + d' + 1 := by omega
change (towerAlgebraMap (l:=i) (r:=j) (h_le:=by omega)) x =
join_via_add_smul (h_pos:=by omega) 0 ((towerAlgebraMap (l:=i) (r:=j-1) (h_le:=by omega)) x)
rw! [h_j_eq]
rw [towerAlgebraMap_succ (l:=i) (r:=i+d') (h_le:=by omega)]
simp only [RingHom.coe_comp, Function.comp_apply, Nat.add_one_sub_one]
set r := towerAlgebraMap (l:=i) (r:=i+d') (h_le:=by omega) x with h_r
have h := algebraMap_succ_eq_zero_x (k:=i+d'+1) (h_pos:=by omega) r
simp only [Nat.add_one_sub_one] at h
rw [←h]
rfl | 8 | 114 | false | Applied verif. |
55 | Nat.getBit_of_sub_two_pow_of_bit_1 | lemma getBit_of_sub_two_pow_of_bit_1 {n i j: ℕ} (h_getBit_eq_1: getBit i n = 1) :
getBit j (n - 2^i) = (if j = i then 0 else getBit j n) | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Nat.testBit",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "Nat.binaryRec",
"module": "Mathlib.Data.Nat.B... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Bool.toNat_true",
"module": "Init.Data.Bool"
},
{
"name": "Nat.and_one_is_mod",
"module": "Init.Data.Nat.Bitwise.Lemmas"
},
{
"name": "Nat.and_two_pow",
"module": "Mathlib.Data.Nat.Bitwise"
},
{
"name": "Nat.mod_two_bne_zero",
"module": "Init.Data.Nat.Lemmas"
... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
}
] | [
{
"name": "Nat.testBit_true_eq_getBit_eq_1",
"content": "lemma testBit_true_eq_getBit_eq_1 (k n : Nat) : n.testBit k = ((Nat.getBit k n) = 1)"
},
{
"name": "Nat.getBit_two_pow",
"content": "lemma getBit_two_pow {i k : ℕ} : (getBit k (2^i) = if i == k then 1 else 0)"
},
{
"name": "Nat.and... | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1 | lemma getBit_of_sub_two_pow_of_bit_1 {n i j: ℕ} (h_getBit_eq_1: getBit i n = 1) :
getBit j (n - 2^i) = (if j = i then 0 else getBit j n) := | := by
have h_2_pow_i_lt_n: 2^i ≤ n := by
apply Nat.ge_two_pow_of_testBit
rw [Nat.testBit_true_eq_getBit_eq_1]
exact h_getBit_eq_1
have h_xor_eq_sub := (Nat.xor_eq_sub_iff_submask (n:=n) (m:=2^i) (h_2_pow_i_lt_n)).mpr (by
exact and_two_pow_eq_two_pow_of_getBit_1 h_getBit_eq_1)
rw [h_xor_eq_sub.symm]
rw [Nat.getBit_of_xor]
if h_j_eq_i: j = i then
rw [h_j_eq_i]
rw [h_getBit_eq_1]
rw [Nat.getBit_two_pow]
simp only [BEq.rfl, ↓reduceIte, Nat.xor_self]
else
rw [Nat.getBit_two_pow]
simp only [beq_iff_eq]
simp only [h_j_eq_i, ↓reduceIte]
push_neg at h_j_eq_i
simp only [if_neg h_j_eq_i.symm, xor_zero] | 4 | 78 | false | Applied verif. |
56 | Binius.BinaryBasefold.toOutCodewordsCount_succ_eq | lemma toOutCodewordsCount_succ_eq (i : Fin ℓ) :
(toOutCodewordsCount ℓ ϑ i.succ) =
if isCommitmentRound ℓ ϑ i then (toOutCodewordsCount ℓ ϑ i.castSucc) + 1
else (toOutCodewordsCount ℓ ϑ i.castSucc) | ArkLib | ArkLib/ProofSystem/Binius/BinaryBasefold/Basic.lean | [
"import ArkLib.ProofSystem.Binius.BinaryBasefold.Prelude"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Decidable",
"module": "Init.Prelude"
},
{
"name": "False.elim",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Ne",... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.succ_div_of_dvd",
"module": "Init.Data.Nat.Div.Lemmas"
},
{
"name": "Nat.succ_div_of_not_dvd",
"module": "Init.Data.Nat.Div.Lemmas"
},
{
"name": "Fin.coe_castSucc",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.val_pos_iff",
"module": "Mathlib.Data.Fin... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Binius.BinaryBasefold.toOutCodewordsCount",
"content": "def toOutCodewordsCount (i : Fin (ℓ + 1)) : ℕ :="
},
{
"name": "Binius.BinaryBasefold.isCommitmentRound",
"content": "def isCommitmentRound (i : Fin ℓ) : Prop :=\n ϑ ∣ i.val + 1 ∧ i.val + 1 ≠ ℓ"
}
] | [
{
"name": "Binius.BinaryBasefold.div_add_one_eq_if_dvd",
"content": "lemma div_add_one_eq_if_dvd (i ϑ : ℕ) [NeZero ϑ] :\n (i + 1) / ϑ = if ϑ ∣ i + 1 then i / ϑ + 1 else i / ϑ"
},
{
"name": "Binius.BinaryBasefold.toOutCodewordsCount_succ_eq_add_one_iff",
"content": "omit hdiv in\nlemma toOutCo... | import ArkLib.ProofSystem.Binius.BinaryBasefold.Prelude
noncomputable section
namespace Binius.BinaryBasefold
open OracleSpec OracleComp ProtocolSpec Finset AdditiveNTT Polynomial MvPolynomial
Binius.BinaryBasefold
open scoped NNReal
open ReedSolomon Code BerlekampWelch
open Finset AdditiveNTT Polynomial MvPolynomial Nat Matrix
variable {L : Type} [CommRing L] (ℓ : ℕ) [NeZero ℓ]
variable (𝓑 : Fin 2 ↪ L)
section OracleStatementIndex
variable (ℓ : ℕ) (ϑ : ℕ) [NeZero ℓ] [NeZero ϑ] [hdiv : Fact (ϑ ∣ ℓ)]
def toOutCodewordsCount (i : Fin (ℓ + 1)) : ℕ :=
def isCommitmentRound (i : Fin ℓ) : Prop :=
ϑ ∣ i.val + 1 ∧ i.val + 1 ≠ ℓ
open Classical in | lemma toOutCodewordsCount_succ_eq (i : Fin ℓ) :
(toOutCodewordsCount ℓ ϑ i.succ) =
if isCommitmentRound ℓ ϑ i then (toOutCodewordsCount ℓ ϑ i.castSucc) + 1
else (toOutCodewordsCount ℓ ϑ i.castSucc) := | := by
have h_succ_val: i.succ.val = i.val + 1 := rfl
by_cases hv: ϑ ∣ i.val + 1 ∧ i.val + 1 ≠ ℓ
· have h_succ := (toOutCodewordsCount_succ_eq_add_one_iff ℓ ϑ i).mp hv
rw [←h_succ];
simp only [left_eq_ite_iff, Nat.add_eq_left, one_ne_zero, imp_false, Decidable.not_not]
exact hv
· rw [isCommitmentRound]
simp [ne_eq, hv, ↓reduceIte]
unfold toOutCodewordsCount
have h_i_lt_ℓ: i.castSucc.val < ℓ := by
change i.val < ℓ
omega
simp only [Fin.val_succ, Fin.coe_castSucc, Fin.is_lt, ↓reduceIte]
rw [div_add_one_eq_if_dvd]
by_cases hv_div_succ: ϑ ∣ i.val + 1
· simp only [hv_div_succ, ↓reduceIte, Nat.add_eq_left, ite_eq_right_iff, one_ne_zero,
imp_false, not_lt, ge_iff_le]
simp only [hv_div_succ, ne_eq, true_and, Decidable.not_not] at hv
have h_eq: i.succ.val = ℓ := by
change i.succ.val = (⟨ℓ, by omega⟩: Fin (ℓ + 1)).val
exact hv
omega
· simp only [hv_div_succ, ↓reduceIte, Nat.add_left_cancel_iff, ite_eq_left_iff, not_lt,
zero_ne_one, imp_false, not_le, gt_iff_lt]
if hi_succ_lt: i.succ.val < ℓ then
omega
else
simp only [Fin.val_succ, not_lt] at hi_succ_lt
have hi_succ_le_ℓ: i.succ.val ≤ ℓ := by omega
have hi_succ_eq_ℓ: i.val + 1 = ℓ := by omega
rw [hi_succ_eq_ℓ] at hv_div_succ
exact False.elim (hv_div_succ (hdiv.out)) | 3 | 53 | false | Applied verif. |
57 | AdditiveNTT.evalWAt_eq_W | theorem evalWAt_eq_W (i : Fin r) (x : L) :
evalWAt (β := β) (ℓ := ℓ) (R_rate := R_rate) (i := i) x =
(W (𝔽q := 𝔽q) (β := β) (i := i)).eval x | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Impl",
"import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT",
"import ArkLib.Data.Nat.Bitwise",
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "split",
"content": "def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :\n ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=\n let lo_bits : BitVec (2 ^ (k - 1) - 1 -... | [
{
"name": "Bool.false_eq_true",
"module": "Init.Data.Bool"
},
{
"name": "Fact.out",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Finset.mem_univ",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Finset.sum_congr",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "eq_iff_eq_all_getBits",
"content": "lemma eq_iff_eq_all_getBits {n m : ℕ} : n = m ↔ ∀ k, getBit k n = getBit k m"
},
{
"name": "getBit... | [
{
"name": "AdditiveNTT.bitsToU",
"content": "def bitsToU (i : Fin r) (k : Fin (2 ^ i.val)) :\n AdditiveNTT.U (L := L) (𝔽q := 𝔽q) (β := β) i :=\n let val := (Finset.univ : Finset (Fin i)).sum fun j =>\n if (Nat.getBit (n := k.val) (k := j.val) == 1) then\n β ⟨j, by admit /- proof elided -/\n ... | [
{
"name": "AdditiveNTT.List.prod_finRange_eq_finset_prod",
"content": "lemma List.prod_finRange_eq_finset_prod {M : Type*} [CommMonoid M] {n : ℕ} (f : Fin n → M) :\n ((List.finRange n).map f).prod = ∏ i : Fin n, f i"
},
{
"name": "AdditiveNTT.bitsToU_bijective",
"content": "theorem bitsToU_bi... | import ArkLib.Data.FieldTheory.AdditiveNTT.AdditiveNTT
import ArkLib.Data.FieldTheory.BinaryField.Tower.Impl
namespace AdditiveNTT
open ConcreteBinaryTower
section HelperFunctions
end HelperFunctions
variable {r : ℕ} [NeZero r]
variable {L : Type} [Field L] [Fintype L] [DecidableEq L]
variable {𝔽q : Type} [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
variable [hFq_card : Fact (Fintype.card 𝔽q = 2)]
variable [h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
variable [h_β₀_eq_1 : Fact (β 0 = 1)]
section Algorithm
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
def bitsToU (i : Fin r) (k : Fin (2 ^ i.val)) :
AdditiveNTT.U (L := L) (𝔽q := 𝔽q) (β := β) i :=
let val := (Finset.univ : Finset (Fin i)).sum fun j =>
if (Nat.getBit (n := k.val) (k := j.val) == 1) then
β ⟨j, by admit /- proof elided -/
⟩
else 0
⟨val, by admit /- proof elided -/
⟩
def getUElements (i : Fin r) : List L :=
(List.finRange (2^i.val)).map fun k =>
(Finset.univ : Finset (Fin i)).sum fun j =>
if Nat.getBit (n := k.val) (k := j.val) == 1 then
β ⟨j.val, by admit /- proof elided -/
⟩
else 0
def evalWAt (i : Fin r) (x : L) : L :=
((getUElements (β := β) (ℓ := ℓ) (R_rate := R_rate) i).map (fun u => x - u)).prod | theorem evalWAt_eq_W (i : Fin r) (x : L) :
evalWAt (β := β) (ℓ := ℓ) (R_rate := R_rate) (i := i) x =
(W (𝔽q := 𝔽q) (β := β) (i := i)).eval x := | := by
-- 1. Convert implementation to mathematical product over Fin(2^i)
unfold evalWAt getUElements
rw [List.map_map]
rw [List.prod_finRange_eq_finset_prod] -- Now the pattern matches!
-- 2. Prepare RHS
rw [AdditiveNTT.W, Polynomial.eval_prod]
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C]
-- 3. Use Finset.prod_bij to show equality via the bijection
-- LHS: ∏ k : Fin(2^i), (x - bitsToU k), RHS: ∏ u : U i, (x - u)
apply Finset.prod_bij (s := ((Finset.univ (α := (Fin (2^(i.val)))))))
(t := (Finset.univ : Finset (U 𝔽q β i)))
(i := fun k _ =>
bitsToU (𝔽q := 𝔽q) (β := β) (ℓ := ℓ) (r := r) (R_rate := R_rate) (L := L) (i := i) k)
(hi := by
-- Proof that the map lands in the target set (Finset.univ)
intro a _
exact Finset.mem_univ _)
(i_inj := by
-- Proof of Injectivity (uses our previous theorem)
intro a₁ _ a₂ _ h_eq
exact (bitsToU_bijective (𝔽q := 𝔽q) (β := β) (ℓ := ℓ)
(r := r) (R_rate := R_rate) (L := L) (i := i)).1 h_eq)
(i_surj := by
-- Proof of Surjectivity (uses our previous theorem)
intro b _
-- We need to provide the element 'a' and the proof it is in the set
obtain ⟨a, ha_eq⟩ := (bitsToU_bijective (𝔽q := 𝔽q)
(β := β) (ℓ := ℓ) (r := r) (R_rate := R_rate) (L := L) (i := i)).2 b
use a
constructor
· exact ha_eq
· exact Finset.mem_univ a
)
(h := by -- Proof that the values are equal: (x - bitsToU k) = (x - (bitsToU k))
intro a ha_univ
rfl
) | 4 | 73 | false | Applied verif. |
58 | AdditiveNTT.normalizedW_eq_qMap_composition | lemma normalizedW_eq_qMap_composition (ℓ R_rate : ℕ) (i : Fin r) :
normalizedW 𝔽q β i = qCompositionChain 𝔽q β (ℓ:=ℓ) (R_rate:=R_rate) i | ArkLib | ArkLib/Data/FieldTheory/AdditiveNTT/AdditiveNTT.lean | [
"import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis",
"import Mathlib.Data.Finsupp.Defs",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Tactic",
"import ArkLib.Data.Polynomial.Frobenius",
"import Mathlib.LinearAlgebra.LinearIndependent.Defs"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Subspace",
"module": "Mathlib.Algebra.Module.Submodule.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ico",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Submodule"... | [
{
"name": "W",
"content": "noncomputable def W (i : Fin r) : L[X] :=\n ∏ u : U 𝔽q β i, (X - C u.val)"
},
{
"name": "U",
"content": "def U (i : Fin r) : Subspace 𝔽q L := Submodule.span 𝔽q (β '' (Set.Ico 0 i))"
},
{
"name": "normalizedW",
"content": "noncomputable def normalizedW (... | [
{
"name": "Fintype.card_pos",
"module": "Mathlib.Data.Fintype.Card"
},
{
"name": "Polynomial.C_1",
"module": "Mathlib.Algebra.Polynomial.Basic"
},
{
"name": "Polynomial.C_comp",
"module": "Mathlib.Algebra.Polynomial.Eval.Defs"
},
{
"name": "Polynomial.C_mul",
"module": "M... | [
{
"name": "Xⱼ_zero_eq_one",
"content": "lemma Xⱼ_zero_eq_one (ℓ : ℕ) (h_ℓ : ℓ ≤ r) :\n Xⱼ 𝔽q β ℓ h_ℓ ⟨0, by exact Nat.two_pow_pos ℓ⟩ = 1"
},
{
"name": "W_linear_comp_decomposition",
"content": "omit hF₂ in\ntheorem W_linear_comp_decomposition (i : Fin r) (h_i_add_1 : i + 1 < r) :\n ∀ p: L[X... | [
{
"name": "AdditiveNTT.qMap",
"content": "noncomputable def qMap (i : Fin r) : L[X] :=\n let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)\n / ((W 𝔽q β (i + 1)).eval (β (i + 1)))\n C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))"
},
{
"name": "AdditiveNTT.qCompositi... | [
{
"name": "AdditiveNTT.qMap_comp_normalizedW",
"content": "lemma qMap_comp_normalizedW (i : Fin r) (h_i_add_1 : i + 1 < r) :\n (qMap 𝔽q β i).comp (normalizedW 𝔽q β i) = normalizedW 𝔽q β (i + 1)"
}
] | import ArkLib.Data.FieldTheory.AdditiveNTT.NovelPolynomialBasis
import Mathlib.Tactic
import Mathlib.Data.Finsupp.Defs
import Mathlib.LinearAlgebra.LinearIndependent.Defs
open Polynomial AdditiveNTT Module
namespace AdditiveNTT
variable {r : ℕ} [NeZero r]
variable {L : Type u} [Field L] [Fintype L] [DecidableEq L]
variable (𝔽q : Type u) [Field 𝔽q] [Fintype 𝔽q] [DecidableEq 𝔽q]
[h_Fq_char_prime : Fact (Nat.Prime (ringChar 𝔽q))] [hF₂ : Fact (Fintype.card 𝔽q = 2)]
variable [Algebra 𝔽q L]
variable (β : Fin r → L) [hβ_lin_indep : Fact (LinearIndependent 𝔽q β)]
[h_β₀_eq_1 : Fact (β 0 = 1)]
variable {ℓ R_rate : ℕ} (h_ℓ_add_R_rate : ℓ + R_rate < r)-- ℓ ∈ {1, ..., r-1}
section IntermediateStructures
noncomputable def qMap (i : Fin r) : L[X] :=
let constMultiplier := ((W 𝔽q β i).eval (β i))^(Fintype.card 𝔽q)
/ ((W 𝔽q β (i + 1)).eval (β (i + 1)))
C constMultiplier * ∏ c: 𝔽q, (X - C (algebraMap 𝔽q L c))
noncomputable def qCompositionChain (i : Fin r) : L[X] :=
match i with
| ⟨0, _⟩ => X
| ⟨k + 1, h_k_add_1⟩ => (qMap 𝔽q β ⟨k, by admit /- proof elided -/
⟩).comp (qCompositionChain ⟨k, by admit /- proof elided -/
⟩) | lemma normalizedW_eq_qMap_composition (ℓ R_rate : ℕ) (i : Fin r) :
normalizedW 𝔽q β i = qCompositionChain 𝔽q β (ℓ:=ℓ) (R_rate:=R_rate) i := | :=
by
-- We proceed by induction on i.
induction i using Fin.succRecOnSameFinType with
| zero =>
-- Base case: i = 0
-- We need to show `normalizedW ... 0 = qCompositionChain 0`.
-- The RHS is `X` by definition of the chain.
rw [qCompositionChain.eq_def]
-- The LHS is `C (1 / eval (β 0) (W ... 0)) * (W ... 0)`.
rw [normalizedW, W₀_eq_X, eval_X, h_β₀_eq_1.out, div_one, C_1, one_mul]
rfl
| succ k k_h i_h =>
-- Inductive step: Assume the property holds for k, prove for k+1.
-- The goal is `normalizedW ... (k+1) = qCompositionChain (k+1)`.
-- The RHS is `(qMap k).comp (qCompositionChain k)` by definition.
rw [qCompositionChain.eq_def]
-- From Lemma 4.2, we know `normalizedW ... (k+1) = (qMap k).comp (normalizedW ... k)`.
-- How to choose the rhs?
have h_eq: ⟨k.val.succ, k_h⟩ = k + 1 := by
rw [Fin.mk_eq_mk]
rw [Fin.val_add_one']
exact k_h
simp only [h_eq.symm, Nat.succ_eq_add_one, Fin.eta]
have h_res := qMap_comp_normalizedW 𝔽q β k k_h
-- ⊢ normalizedW 𝔽q β ⟨↑k + 1, k_h⟩ = (qMap 𝔽q β k).comp (qCompositionChain 𝔽q β k)
rw [←i_h]
rw [h_res]
simp only [h_eq] | 11 | 86 | false | Applied verif. |
59 | Nat.getHighBits_no_shl_joinBits | lemma getHighBits_no_shl_joinBits {n m : ℕ} (low : Fin (2 ^ n)) (high : Fin (2 ^ m)) :
getHighBits_no_shl n (joinBits low high).val = high.val | ArkLib | ArkLib/Data/Nat/Bitwise.lean | [
"import Mathlib.Algebra.Order.BigOperators.Group.Finset",
"import ArkLib.Data.Fin.BigOperators",
"import Mathlib.Algebra.BigOperators.Ring.Finset",
"import Mathlib.Data.Nat.Bitwise",
"import Mathlib.Data.Finsupp.Basic",
"import Mathlib.Algebra.Order.Ring.Star",
"import Mathlib.Data.Nat.Digits.Defs",
"... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Nat.binaryRec",
"module": "Mathlib.Data.Nat.BinaryRec"
},
{
"name": "Nat.bit",
"module": "Mathlib.Data.Nat.Binary... | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.add_mul_div_left",
"module": "Init.Data.Nat.Div.Basic"
},
{
"name": "add_comm",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "mul_comm",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Nat.and_div_two_pow",
"module": "Init.Data.Nat.Bitwise.Lemma... | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Nat.getBit",
"content": "def getBit (k n : Nat) : Nat := (n >>> k) &&& 1"
},
{
"name": "Nat.getHighBits_no_shl",
"content": "def getHighBits_no_shl (numLowBits : ℕ) (n : ℕ) : ℕ := n >>> numLowBits"
},
{
"name": "Nat.joinBits",
"content": "def joinBits {n m : ℕ} (low : Fin ... | [
{
"name": "Nat.getBit_lt_2",
"content": "lemma getBit_lt_2 {k n : Nat} : getBit k n < 2"
},
{
"name": "Nat.getBit_eq_testBit",
"content": "lemma getBit_eq_testBit (k n : Nat) : getBit k n = if n.testBit k then 1 else 0"
},
{
"name": "Nat.eq_iff_eq_all_getBits",
"content": "lemma eq_i... | import ArkLib.Data.Fin.BigOperators
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Digits.Defs
import Mathlib.Data.Finsupp.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Fin
namespace Nat
def getBit (k n : Nat) : Nat := (n >>> k) &&& 1
def getHighBits_no_shl (numLowBits : ℕ) (n : ℕ) : ℕ := n >>> numLowBits
def joinBits {n m : ℕ} (low : Fin (2 ^ n)) (high : Fin (2 ^ m)) : Fin (2 ^ (m+n)) :=
⟨(high.val <<< n) ||| low.val, by admit /- proof elided -/
⟩ | lemma getHighBits_no_shl_joinBits {n m : ℕ} (low : Fin (2 ^ n)) (high : Fin (2 ^ m)) :
getHighBits_no_shl n (joinBits low high).val = high.val := | := by
unfold joinBits getHighBits_no_shl
dsimp
have h_and_zero := and_shl_eq_zero_of_lt_two_pow (a := high.val) (b := low.val) (hb := low.isLt)
rw [←Nat.sum_of_and_eq_zero_is_or h_and_zero]
rw [Nat.add_shiftRight_distrib h_and_zero]
rw [Nat.shiftLeft_shiftRight]
rw [Nat.shiftRight_eq_div_pow]
have h: low.val/2^n = 0 := by
apply Nat.div_eq_zero_iff_lt (x:=low) (k:=2^n) (h:=by exact Nat.two_pow_pos n).mpr (by omega)
simp only [h, add_zero] | 4 | 97 | false | Applied verif. |
60 | ConcreteBinaryTower.towerRingHomForwardMap_backwardMap_eq | lemma towerRingHomForwardMap_backwardMap_eq (k : ℕ) (x : BTField k) :
towerRingHomForwardMap (k:=k) (towerRingHomBackwardMap (k:=k) x) = x | ArkLib | ArkLib/Data/FieldTheory/BinaryField/Tower/Impl.lean | [
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Prelude",
"import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic",
"import ArkLib.Data.Classes.DCast"
] | [
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BitVec.cast",
"module": "Init.Data.BitVec.Basic"
},
{
"name"... | [
{
"name": "GaloisField",
"content": "notation : 10 \"GF(\" term : 10 \")\" => GaloisField term 1"
},
{
"name": "DCast",
"content": "class DCast (α : Sort*) (β : α → Sort*) where\n dcast : ∀ {a a' : α}, a = a' → β a → β a'\n dcast_id : ∀ {a : α}, dcast (Eq.refl a) = id"
},
{
"name": "su... | [
{
"name": "Nat.sub_add_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.sub_zero",
"module": "Init.Data.Nat.Basic"
},
{
"name": "BitVec.ofNat_toNat",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "BitVec.setWidth_eq",
"module": "Init.Data.BitVec.Lemmas"
... | [
{
"name": "one_le_two_pow_n",
"content": "theorem one_le_two_pow_n (n : ℕ) : 1 ≤ 2 ^ n"
},
{
"name": "dcast_eq",
"content": "@[simp]\ntheorem dcast_eq : dcast (Eq.refl a) b = b"
},
{
"name": "one_le_sub_consecutive_two_pow",
"content": "theorem one_le_sub_consecutive_two_pow (n : ℕ):... | [
{
"name": "ConcreteBinaryTower.ConcreteBTField",
"content": "def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)"
},
{
"name": "ConcreteBinaryTower.BitVec",
"content": "instance BitVec.instDCast : DCast Nat BitVec where\n dcast h := BitVec.cast h\n dcast_id := by admit /- proof elided -/... | [
{
"name": "ConcreteBinaryTower.cast_ConcreteBTField_eq",
"content": "lemma cast_ConcreteBTField_eq (k m : ℕ) (h_eq : k = m) :\n ConcreteBTField k = ConcreteBTField m"
},
{
"name": "ConcreteBinaryTower.BitVec.dcast_id",
"content": "theorem BitVec.dcast_id {n : Nat} (bv : BitVec n) :\n DCast.dca... | import ArkLib.Data.Classes.DCast
import ArkLib.Data.FieldTheory.BinaryField.Tower.Basic
namespace ConcreteBinaryTower
open Polynomial
def ConcreteBTField : ℕ → Type := fun k => BitVec (2 ^ k)
section BitVecDCast
instance BitVec.instDCast : DCast Nat BitVec where
dcast h := BitVec.cast h
dcast_id := by admit /- proof elided -/
end BitVecDCast
section ConversionUtils
def fromNat {k : ℕ} (n : Nat) : ConcreteBTField k :=
BitVec.ofNat (2 ^ k) n
instance ConcreteBTField.instDCast_local : DCast ℕ ConcreteBTField where
dcast h_k_eq term_k1 := BitVec.cast (congrArg (fun n => 2 ^ n) h_k_eq) term_k1
dcast_id := by admit /- proof elided -/
end ConversionUtils
section NumericLemmas
end NumericLemmas
section FieldOperationsAndInstances
def zero {k : ℕ} : ConcreteBTField k := BitVec.zero (2 ^ k)
def one {k : ℕ} : ConcreteBTField k := 1#(2 ^ k)
def add {k : ℕ} (x y : ConcreteBTField k) : ConcreteBTField k := BitVec.xor x y
def neg {k : ℕ} (x : ConcreteBTField k) : ConcreteBTField k := x
def split {k : ℕ} (h : k > 0) (x : ConcreteBTField k) :
ConcreteBTField (k - 1) × ConcreteBTField (k - 1) :=
let lo_bits : BitVec (2 ^ (k - 1) - 1 - 0 + 1) :=
BitVec.extractLsb (hi := 2 ^ (k - 1) - 1) (lo := 0) x
let hi_bits : BitVec (2 ^ k - 1 - 2 ^ (k - 1) + 1) :=
BitVec.extractLsb (hi := 2 ^ k - 1) (lo := 2 ^ (k - 1)) x
have h_lo : 2 ^ (k - 1) - 1 - 0 + 1 = 2 ^ (k - 1) := by admit /- proof elided -/
def join {k : ℕ} (h_pos : k > 0) (hi lo : ConcreteBTField (k - 1)) : ConcreteBTField k :=
structure ConcreteBTFAddCommGroupProps (k : ℕ) where
add_assoc : ∀ a b c : ConcreteBTField k, (a + b) + c = a + (b + c) := add_assoc
add_comm : ∀ a b : ConcreteBTField k, a + b = b + a := add_comm
add_zero : ∀ a : ConcreteBTField k, a + zero = a := add_zero
zero_add : ∀ a : ConcreteBTField k, zero + a = a := zero_add
add_neg : ∀ a : ConcreteBTField k, a + (neg a) = zero := neg_add_cancel
def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) := {
zero := zero
neg := neg
sub := fun x y => add x y
add_assoc := add_assoc
add_comm := add_comm
zero_add := zero_add
add_zero := add_zero
nsmul := fun n x => if n % 2 = (0 : ℕ) then zero else x
zsmul := fun (n : ℤ) x => if n % 2 = 0 then zero else x
neg_add_cancel := neg_add_cancel
nsmul_succ := nsmul_succ
zsmul_succ' := fun n a => zsmul_succ n a
add := add
zsmul_neg' := zsmul_neg' (k := k)
}
def Z (k : ℕ) : ConcreteBTField k :=
if h_k : k = 0 then one
else
《 one (k:=k-1), zero (k:=k-1) 》
def equivProd {k : ℕ} (h_k_pos : k > 0) :
ConcreteBTField k ≃ ConcreteBTField (k - 1) × ConcreteBTField (k - 1) where
toFun := split h_k_pos
invFun := fun (hi, lo) => 《 hi, lo 》
left_inv := fun x => Eq.symm (join_of_split h_k_pos x _ _ rfl)
right_inv := fun ⟨hi, lo⟩ => Eq.symm (split_of_join h_k_pos _ hi lo rfl)
def concrete_mul {k : ℕ} (a b : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = zero then zero
else if b = zero then zero
else if a = one then b
else if b = one then a
else zero
else
have h_k_gt_0 : k > 0 := by admit /- proof elided -/
def concrete_inv {k : ℕ} (a : ConcreteBTField k) : ConcreteBTField k :=
if h_k_zero : k = 0 then
if a = 0 then 0 else 1
else
if h_a_zero : a = 0 then 0
else if h_a_one : a = 1 then 1
else
let h_k_gt_0 : k > 0 := Nat.zero_lt_of_ne_zero h_k_zero
let (a_hi, a_lo) := split (k:=k) (h:=h_k_gt_0) a
let prevZ := Z (k - 1)
let a_lo_next := a_lo + concrete_mul a_hi prevZ
let delta := concrete_mul a_lo a_lo_next + concrete_mul a_hi a_hi
let delta_inverse := concrete_inv delta
let out_hi := concrete_mul delta_inverse a_hi
let out_lo := concrete_mul delta_inverse a_lo_next
let res := 《 out_hi, out_lo 》
res
section FieldLemmasOfLevel0
end FieldLemmasOfLevel0
section NumericCasting
def natCast {k : ℕ} (n : ℕ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def natCast_zero {k : ℕ} : natCast (k:=k) 0 = zero :=
def natCast_succ {k : ℕ} (n : ℕ) : natCast (k:=k) (n + 1) = natCast (k:=k) n + 1 :=
def intCast {k : ℕ} (n : ℤ) : ConcreteBTField k := if n % 2 = 0 then zero else one
def intCast_ofNat {k : ℕ} (n : ℕ) : intCast (k:=k) (n : ℤ) = natCast n :=
def intCast_negSucc {k : ℕ} (n : ℕ) : intCast (k:=k) (Int.negSucc n)
= - (↑(n + 1) : ConcreteBTField k) :=
end NumericCasting
structure ConcreteBTFRingProps (k : ℕ) extends (ConcreteBTFAddCommGroupProps k) where
mul_eq : ∀ (a b : ConcreteBTField k) (h_k : k > 0)
{a₁ a₀ b₁ b₀ : ConcreteBTField (k - 1)}
(_h_a : (a₁, a₀) = split h_k a) (_h_b : (b₁, b₀) = split h_k b),
concrete_mul a b =
《 concrete_mul a₀ b₁ + concrete_mul b₀ a₁ + concrete_mul (concrete_mul a₁ b₁) (Z (k - 1)),
concrete_mul a₀ b₀ + concrete_mul a₁ b₁ 》
zero_mul : ∀ a : ConcreteBTField k, concrete_mul zero a = zero
zero_mul' : ∀ a : ConcreteBTField k, concrete_mul 0 a = 0
mul_zero : ∀ a : ConcreteBTField k, concrete_mul a zero = zero
mul_zero' : ∀ a : ConcreteBTField k, concrete_mul a 0 = 0
one_mul : ∀ a : ConcreteBTField k, concrete_mul one a = a
mul_one : ∀ a : ConcreteBTField k, concrete_mul a one = a
mul_assoc : ∀ a b c : ConcreteBTField k, concrete_mul (concrete_mul a b) c
= concrete_mul a (concrete_mul b c)
mul_left_distrib : ∀ a b c : ConcreteBTField k, concrete_mul a (b + c)
= concrete_mul a b + concrete_mul a c
mul_right_distrib : ∀ a b c : ConcreteBTField k, concrete_mul (a + b) c
= concrete_mul a c + concrete_mul b c
structure ConcreteBTFDivisionRingProps (k : ℕ) extends (ConcreteBTFRingProps k) where
mul_inv_cancel : ∀ a : ConcreteBTField k, a ≠ zero → concrete_mul a (concrete_inv a) = one
structure ConcreteBTFieldProps (k : ℕ) extends (ConcreteBTFDivisionRingProps k) where
mul_comm : ∀ a b : ConcreteBTField k, concrete_mul a b = concrete_mul b a
def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where
toAddCommGroup := mkAddCommGroupInstance
toOne := inferInstance
mul := concrete_mul
mul_assoc := props.mul_assoc
one_mul := props.one_mul
mul_one := props.mul_one
left_distrib := props.mul_left_distrib
right_distrib := props.mul_right_distrib
zero_mul := props.zero_mul
mul_zero := props.mul_zero
natCast n := natCast n
natCast_zero := natCast_zero
natCast_succ n := natCast_succ n
intCast n := intCast n
intCast_ofNat n := intCast_ofNat n
intCast_negSucc n := intCast_negSucc n
def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k)
: DivisionRing (ConcreteBTField k) where
toRing := mkRingInstance (k:=k) props
inv := concrete_inv
exists_pair_ne := concrete_exists_pair_ne (k := k)
mul_inv_cancel := props.mul_inv_cancel
inv_zero := concrete_inv_zero
qsmul := (Rat.castRec · * ·)
nnqsmul := (NNRat.castRec · * ·)
def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where
toDivisionRing := mkDivisionRingInstance (k:=k) props
mul_comm := props.mul_comm
structure ConcreteBTFStepResult (k : ℕ) extends (ConcreteBTFieldProps k) where
instFintype : Fintype (ConcreteBTField k)
fieldFintypeCard : Fintype.card (ConcreteBTField k) = 2^(2^k)
sumZeroIffEq : ∀ (x y : ConcreteBTField k), x + y = 0 ↔ x = y
traceMapEvalAtRootsIs1 :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
TraceMapProperty (ConcreteBTField k) (u:=Z k) k
instIrreduciblePoly :
letI := mkFieldInstance (k:=k) (props:=toConcreteBTFieldProps)
(Irreducible (p := (definingPoly (s:=(Z k)))))
end FieldOperationsAndInstances
section BTFieldPropsOneLevelLiftingLemmas
variable {k : ℕ} {h_k : k > 0}
end BTFieldPropsOneLevelLiftingLemmas
section TowerFieldsConstruction
def liftBTFieldProps (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
ConcreteBTFieldProps (k + 1) := {
zero_mul := concrete_zero_mul (prevBTFResult.toConcreteBTFieldProps),
zero_mul' := fun a => by admit /- proof elided -/
def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k := k)) :
Field (ConcreteBTField (k + 1)) :=
def concreteCanonicalEmbedding (k : ℕ)
(prevBTFieldProps : ConcreteBTFieldProps (k := (k)))
(curBTFieldProps : ConcreteBTFieldProps (k := (k + 1))) :
letI := mkFieldInstance prevBTFieldProps
letI := mkFieldInstance curBTFieldProps
ConcreteBTField k →+* ConcreteBTField (k + 1) :=
instance instAlgebraLiftConcreteBTField (k : ℕ)
(prevBTFResult : ConcreteBTFStepResult (k := k)) :
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
Algebra (ConcreteBTField k) (ConcreteBTField (k + 1)) :=
letI := mkFieldInstance (prevBTFResult.toConcreteBTFieldProps)
letI := liftConcreteBTField (k:=k) prevBTFResult
RingHom.toAlgebra (R:=ConcreteBTField k) (S:=ConcreteBTField (k + 1))
(i:=(concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:=prevBTFResult.toConcreteBTFieldProps)
(curBTFieldProps:=liftBTFieldProps (k:=k) (prevBTFResult:=prevBTFResult))))
def getBTFResult (k : ℕ) : ConcreteBTFStepResult k :=
match k with
| 0 =>
let base : ConcreteBTFieldProps 0 := {
mul_eq := fun a b h_k _ _ _ _ _ _ => by admit /- proof elided -/
| c1_one
·
rw [c1_zero] at h_mul
simp at h_mul
·
rcases c2_cases with c2_zero | c2_one
·
rw [c2_zero] at h_mul
simp at h_mul
·
exact ⟨c1_one, c2_one⟩
have specialElement_eq_zero : specialElement = 0 := by admit /- proof elided -/
end TowerFieldsConstruction
section ConcreteBTFieldAlgebraConstruction
def canonicalAlgMap (k : ℕ) := concreteCanonicalEmbedding (k:=k)
(prevBTFieldProps:= ((getBTFResult k).toConcreteBTFieldProps))
(curBTFieldProps:= ((getBTFResult (k + 1)).toConcreteBTFieldProps))
def concreteTowerAlgebraMap (l r : ℕ) (h_le : l ≤ r) :
ConcreteBTField l →+* ConcreteBTField r :=
instance instAlgebraTowerConcreteBTF : AlgebraTower (ConcreteBTField) where
algebraMap := concreteTowerAlgebraMap
commutes' := by admit /- proof elided -/
def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) :
Algebra (ConcreteBTField l) (ConcreteBTField r) := instAlgebraTowerConcreteBTF.toAlgebra h_le
def join_via_add_smul (k : ℕ) (h_pos : k > 0) (hi_btf lo_btf : ConcreteBTField (k - 1)) :
ConcreteBTField k :=
end ConcreteBTFieldAlgebraConstruction
noncomputable section ConcreteMultilinearBasis
open Module
end ConcreteMultilinearBasis
section TowerEquivalence
open BinaryTower
noncomputable def towerEquiv_zero : RingEquiv (R:=GF(2)) (S:=ConcreteBTField 0) := {
toFun := fun x => if x = 0 then 0 else 1,
invFun := fun x => if x = 0 then 0 else 1,
left_inv := fun x => by admit /- proof elided -/
noncomputable def towerRingEquiv0 : BTField 0 ≃+* ConcreteBTField 0 :=
noncomputable def towerRingEquivFromConcrete0 : ConcreteBTField 0 ≃+* BTField 0 :=
noncomputable def towerRingHomForwardMap (k : ℕ) : ConcreteBTField k → BTField k :=
noncomputable def towerRingHomBackwardMap (k : ℕ) : BTField k → ConcreteBTField k := | lemma towerRingHomForwardMap_backwardMap_eq (k : ℕ) (x : BTField k) :
towerRingHomForwardMap (k:=k) (towerRingHomBackwardMap (k:=k) x) = x := | := by
induction k with
| zero =>
unfold towerRingHomForwardMap towerRingHomBackwardMap
simp only [↓reduceDIte, RingEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe]
rcases GF_2_value_eq_zero_or_one x with x_zero | x_one
· rw [x_zero];
unfold towerRingEquivFromConcrete0 -- ⊢ towerRingEquiv0.symm (towerRingEquiv0 0) = 0
exact RingEquiv.symm_apply_apply towerRingEquiv0 0
· rw [x_one];
unfold towerRingEquivFromConcrete0 -- ⊢ towerRingEquiv0.symm (towerRingEquiv0 1) = 1
exact RingEquiv.symm_apply_apply towerRingEquiv0 1
| succ k ih =>
rw [towerRingHomBackwardMap] -- split inner
simp only [Nat.add_eq_zero, one_ne_zero, and_false, ↓reduceDIte,
Nat.add_one_sub_one]
rw [towerRingHomForwardMap] -- split outer
simp only [Nat.add_eq_zero, one_ne_zero, and_false, ↓reduceDIte,
Nat.add_one_sub_one]
apply Eq.symm
rw! [split_join_via_add_smul_eq_iff_split (k:=k + 1)]
simp only
-- apply induction hypothesis
rw [ih, ih]
rw [BinaryTower.eq_join_via_add_smul_eq_iff_split] | 15 | 285 | false | Applied verif. |
61 | Capless.preservation | theorem preservation
(hr : Reduce state state')
(ht : TypedState state Γ E) :
Preserve Γ E state' | capless-lean | Capless/Soundness/Preservation.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Subst.Type.Typing",
"import Capless.Renaming.Capture.Typing",
"import Capless.Weakening.TypedCont.Term",
"import Capless.Basic",
"import Capless.Typing.Basic",
"import Capless.CaptureSet",
"import Capless.Store",
"import Capless.Narrowing.Typing",... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
}
] | [
{
"name": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t",
"content": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t"
},
{
"name": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u",
"content": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u"
},
{
"name": "notat... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Subcapt.refl",
"content": "theorem Subcapt.refl :\n Subcapt Γ C C"
},
{
"name": "ESubtyp.cweaken",
"content": "theorem ESubtyp.cweaken\n (h : ESubtyp Γ E1 E2) :\n ESubtyp (Γ.cvar b) E1.cweaken E2.cweaken"
},
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken... | [
{
"name": "Capless.Preserve",
"content": "inductive Preserve : Context n m k -> EType n m k -> State n' m' k' -> Prop where\n| mk :\n TypedState state Γ E ->\n Preserve Γ E state\n| mk_weaken :\n TypedState state (Γ.var P) E.weaken ->\n Preserve Γ E state\n| mk_tweaken :\n TypedState state (Γ.tvar b) E... | [
{
"name": "Capless.value_typing_widen",
"content": "theorem value_typing_widen\n (hv : Typed Γ v (EType.type (S^C)) Cv)\n (hs : Γ ⊢ (S^C1) <: (S'^C2)) :\n Typed Γ v (S'^C) Cv"
},
{
"name": "Capless.EType.weaken_cweaken_helper",
"content": "theorem EType.weaken_cweaken_helper {S : SType n m k}... | import Capless.Store
import Capless.Type
import Capless.Reduction
import Capless.Inversion.Typing
import Capless.Inversion.Lookup
import Capless.Renaming.Term.Subtyping
import Capless.Renaming.Type.Subtyping
import Capless.Renaming.Capture.Subtyping
import Capless.Subst.Term.Typing
import Capless.Subst.Type.Typing
import Capless.Subst.Capture.Typing
import Capless.Weakening.TypedCont
import Capless.Tactics
import Capless.WellScoped.Basic
import Capless.Narrowing.TypedCont
import Capless.Typing.Boundary
namespace Capless
inductive Preserve : Context n m k -> EType n m k -> State n' m' k' -> Prop where
| mk :
TypedState state Γ E ->
Preserve Γ E state
| mk_weaken :
TypedState state (Γ.var P) E.weaken ->
Preserve Γ E state
| mk_tweaken :
TypedState state (Γ.tvar b) E.tweaken ->
Preserve Γ E state
| mk_cweaken :
TypedState state (Γ.cvar b) E.cweaken ->
Preserve Γ E state
| mk_enter :
TypedState state ((Γ.label S).cvar b) E.weaken.cweaken ->
Preserve Γ E state | theorem preservation
(hr : Reduce state state')
(ht : TypedState state Γ E) :
Preserve Γ E state' := | := by
cases hr
case apply hl =>
cases ht
case mk hs hsc ht hc =>
have hg := TypedStore.is_tight hs
have ⟨T0, Cf, F0, E0, hx, hy, he1, hs1⟩:= Typed.app_inv ht
have ⟨Sv, Cv, Cv0, hv, hbx, hvs⟩ := Store.lookup_inv_typing hl hs hx
have hv' := value_typing_widen hv hvs
have ⟨hcfs, hcft⟩ := Typed.canonical_form_lam hg hv'
constructor
constructor
{ easy }
{ apply Typed.sub
{ apply Typed.open (h := hcft)
exact hy }
{ apply Subcapt.refl }
{ subst he1
easy } }
{ have h1 := Typed.app_inv_capt ht
have h2 := WellScoped.subcapt hsc h1
simp [CaptureSet.open]
simp [FinFun.open, CaptureSet.weaken, CaptureSet.rename_rename]
simp [FinFun.open_comp_weaken, CaptureSet.rename_id]
cases h2; rename_i h2 h3
apply WellScoped.union
{ apply WellScoped.var_inv
exact h2; easy }
{ easy } }
{ easy }
case tapply hl =>
cases ht
case mk hs hsc ht hc =>
have hg := TypedStore.is_tight hs
have ⟨Cf, F, E0, hx, he0, hs0⟩ := Typed.tapp_inv ht
have ⟨Sv, Cv, Cv0, hv, hbx, hvs⟩ := Store.lookup_inv_typing hl hs hx
have hv' := value_typing_widen hv hvs
have ⟨hs1, hft⟩ := Typed.canonical_form_tlam hg hv'
constructor
constructor
{ easy }
{ apply Typed.sub
{ apply Typed.topen (h := hft) }
{ apply Subcapt.refl }
{ subst he0
easy } }
{ have h1 := Typed.tapp_inv_capt ht
have h2 := WellScoped.subcapt hsc h1
apply WellScoped.var_inv
exact h2
easy }
easy
case capply hl =>
cases ht
case mk hs hsc ht hc =>
have hg := TypedStore.is_tight hs
have ⟨Cf, F, E0, hx, he1, hs1⟩ := Typed.capp_inv ht
have ⟨Sv, Cv, Cv0, hv, hbx, hvs⟩ := Store.lookup_inv_typing hl hs hx
have hv' := value_typing_widen hv hvs
have ⟨hsb, hct⟩ := Typed.canonical_form_clam hg hv'
constructor
constructor
{ easy }
{ apply Typed.sub
{ apply Typed.copen hct }
{ apply Subcapt.refl }
{ subst he1
exact hs1 } }
{ have h1 := Typed.capp_inv_capt ht
have h2 := WellScoped.subcapt hsc h1
simp [CaptureSet.cweaken, CaptureSet.copen, CaptureSet.crename_crename]
simp [FinFun.open_comp_weaken, CaptureSet.crename_id]
apply WellScoped.var_inv
exact h2
easy }
easy
case push =>
cases ht
case mk hs hsc ht hc =>
have ⟨T, E0, htt, htu, hsub⟩ := Typed.letin_inv ht
constructor
constructor
{ easy }
{ exact htt }
{ apply WellScoped.cons; easy }
{ constructor
apply Typed.sub <;> try easy
apply Subcapt.refl
apply ESubtyp.weaken; easy
{ easy }
easy }
case push_ex =>
cases ht
case mk hs hsc ht hc =>
have ⟨T, E0, htt, htu, hsub⟩ := Typed.letex_inv ht
constructor
constructor
{ exact hs }
{ exact htt }
{ apply WellScoped.conse; easy }
{ constructor
apply Typed.sub; exact htu; apply Subcapt.refl
apply ESubtyp.weaken
apply ESubtyp.cweaken; exact hsub
{ easy }
exact hc }
case rename =>
cases ht
case mk hs hsc hx hc =>
cases hc
case cons hu hsc0 hc0 =>
have hu1 := hu.open hx
simp [EType.weaken, EType.open] at hu1
simp [EType.rename_rename] at hu1
simp [FinFun.open_comp_weaken] at hu1
simp [EType.rename_id] at hu1
constructor
constructor <;> try easy
simp [CaptureSet.weaken, CaptureSet.open]
simp [CaptureSet.rename_rename]
simp [FinFun.open_comp_weaken, CaptureSet.rename_id]
easy
case lift_ex =>
cases ht
case mk hs hsc ht hc =>
cases hc
case conse hu hsc hc0 =>
have hg := TypedStore.is_tight hs
have hx := Typed.canonical_form_pack hg ht
rename_i C _ _ _ _ _ _ _
have hu1 := hu.cinstantiate_extvar (C := C)
have hu2 := hu1.open hx
simp [EType.weaken, EType.open, EType.rename_rename] at hu2
simp [FinFun.open_comp_weaken] at hu2
simp [EType.rename_id] at hu2
apply Preserve.mk_cweaken
constructor
{ constructor; exact hs }
{ exact hu2 }
{ simp [CaptureSet.weaken, CaptureSet.open]
simp [CaptureSet.rename_rename, FinFun.open_comp_weaken]
simp [CaptureSet.rename_id]
apply hsc.cweaken }
{ apply TypedCont.cweaken; exact hc0 }
case lift hv =>
cases ht
case mk hs hsc ht hc =>
cases hc
case cons hu hsc0 hc0 =>
apply Preserve.mk_weaken
constructor
{ constructor; exact hs; exact ht }
{ exact hu }
{ apply hsc0.weaken }
{ apply TypedCont.weaken; exact hc0 }
case tlift =>
cases ht
case mk hs hsc ht hc =>
apply Preserve.mk_tweaken
have ⟨E0, ht, hsub⟩ := Typed.bindt_inv ht
constructor
{ constructor; exact hs }
{ apply Typed.sub
exact ht; apply Subcapt.refl
apply ESubtyp.tweaken; exact hsub }
{ apply hsc.tweaken }
{ apply TypedCont.tweaken; exact hc }
case clift =>
cases ht
case mk hs hsc ht hc =>
apply Preserve.mk_cweaken
have ⟨E0, ht, hsub⟩ := Typed.bindc_inv ht
constructor
{ constructor; exact hs }
{ apply Typed.sub
exact ht; apply Subcapt.refl
apply ESubtyp.cweaken; exact hsub }
{ apply hsc.cweaken }
{ apply TypedCont.cweaken; exact hc }
case enter =>
cases ht
case mk hs hsc ht hc =>
have ⟨ht0, hsub0⟩ := Typed.boundary_inv ht
apply Preserve.mk_enter
constructor
{ constructor; constructor; easy }
{ apply Typed.boundary_body_typing ht0 }
{ repeat any_goals apply WellScoped.union
{ rw [CaptureSet.weaken_cweaken]
apply WellScoped.scope
apply WellScoped.cweaken
apply WellScoped.lweaken; easy }
{ constructor; constructor
simp
apply WellScoped.label; repeat constructor }
{ apply WellScoped.label; repeat constructor } }
{ constructor; constructor; constructor
rw [<- EType.weaken_cweaken_helper]
apply TypedCont.cweaken
apply TypedCont.lweaken
apply TypedCont.narrow; easy; easy
simp [SType.cweaken, SType.weaken]
rw [SType.crename_rename_comm]
apply CSubtyp.refl }
case leave_var =>
cases ht
case mk hs hsc ht hc =>
have ht1 := Typed.precise_cv ht
apply Preserve.mk
cases hc
rename_i hsub hbl hc0
constructor
{ easy }
{ apply Typed.sub
{ exact ht1 }
{ apply Subcapt.refl }
{ constructor; easy } }
{ have ht1 := Typed.sub ht Subcapt.refl (ESubtyp.type hsub)
have hy := Typed.var_inv_cs ht1
apply WellScoped.subcapt
apply WellScoped.empty
easy }
{ easy }
case leave_val =>
cases ht
case mk hs hsc ht hc =>
rename_i hv _ _ _
cases hc
case scope hsub hbl hc0 =>
have ht1 := Typed.sub ht Subcapt.refl (ESubtyp.type hsub)
have ht2 := Typed.val_precise_cv ht1 hv
apply Preserve.mk
constructor
{ easy }
{ apply Typed.sub
{ exact ht2 }
{ apply Subcapt.refl }
{ apply ESubtyp.refl } }
{ constructor }
{ easy }
case invoke hl hhl =>
cases ht
case mk hs hsc ht hc =>
have hg := TypedStore.is_tight hs
have ⟨S0, C0, hx, hy⟩ := Typed.invoke_inv ht
have h1 := Store.bound_label hl hs
have ⟨S0, hbx, hsub⟩ := Typed.label_inv_sub hx h1 hg
have ⟨Ct1, hc1⟩ := Cont.has_label_tail_inv hc hbx hhl
apply Preserve.mk
constructor
{ easy }
{ exact hy }
{ have hy1 := Typed.var_inv_cs hy
apply WellScoped.subcapt
apply WellScoped.empty
easy }
{ apply hc1.narrow
constructor; constructor
apply Subcapt.refl; easy } | 7 | 334 | false | Type systems |
62 | Capless.Typed.rename | theorem Typed.rename
{Γ : Context n m k} {Δ : Context n' m k}
(h : Typed Γ t E Ct)
(ρ : VarMap Γ f Δ) :
Typed Δ (t.rename f) (E.rename f) (Ct.rename f) | capless-lean | Capless/Renaming/Term/Typing.lean | [
"import Capless.Renaming.Term.Subtyping",
"import Capless.Renaming.Term.Subcapturing",
"import Capless.Typing",
"import Capless.Type.Basic",
"import Capless.CaptureSet",
"import Capless.Renaming.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.Subset.rename",
"content": "theorem CaptureSet.Subset.rename {C1 C2 : CaptureSet n k}\n (h : C1 ⊆ C2) :\n C1.rename f ⊆ C2.rename f"
},
{
"name": "Subcapt.rename",
"content": "theorem Subcapt.rename\n (h : Subcapt Γ C1 C2)\n (ρ : VarMap Γ f Δ) :\n Subcapt Δ (C1.rename ... | [] | [] | import Capless.Typing
import Capless.Renaming.Basic
import Capless.Renaming.Term.Subtyping
namespace Capless | theorem Typed.rename
{Γ : Context n m k} {Δ : Context n' m k}
(h : Typed Γ t E Ct)
(ρ : VarMap Γ f Δ) :
Typed Δ (t.rename f) (E.rename f) (Ct.rename f) := | := by
induction h generalizing n'
case var hb =>
simp [Term.rename, EType.rename, CType.rename]
apply Typed.var
have hb1 := ρ.map _ _ hb
simp [CType.rename] at hb1
trivial
case pack ih =>
simp [Term.rename, EType.rename]
apply Typed.pack
have ih := ih (ρ.cext _)
simp [Term.rename, EType.rename] at ih
exact ih
case sub hsc hs ih =>
apply Typed.sub
apply ih; trivial
apply! hsc.rename
apply! hs.rename
case abs iht =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply Typed.abs
rw [CaptureSet.weaken_rename]
rw [<- CaptureSet.ext_rename_singleton_zero (f := f)]
apply? iht
apply ρ.ext
case tabs iht =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply Typed.tabs
apply? iht
apply ρ.text
case cabs iht =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply Typed.cabs
rw [<- CaptureSet.cweaken_rename_comm]
apply? iht
apply ρ.cext
case app ih1 ih2 =>
simp [Term.rename]
simp [EType.rename_open]
apply Typed.app
have ih1 := ih1 ρ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih1
exact ih1
have ih2 := ih2 ρ
simp [Term.rename, EType.rename] at ih2
exact ih2
case tapp ih =>
simp [Term.rename]
simp [EType.rename_topen]
apply Typed.tapp
have ih := ih ρ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih
trivial
case capp ih =>
simp [Term.rename, EType.rename_copen]
apply Typed.capp
have ih := ih ρ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih
trivial
case letin ih1 ih2 =>
simp [Term.rename]
apply Typed.letin
have ih1 := ih1 ρ
simp [EType.rename] at ih1
exact ih1
have ih2 := ih2 (ρ.ext _)
rw [<- EType.weaken_rename] at ih2
rw [CaptureSet.weaken_rename]
trivial
case letex ih1 ih2 =>
simp [Term.rename]
apply letex
have ih1 := ih1 ρ
simp [EType.rename] at ih1
exact ih1
have ih2 := ih2 ((ρ.cext _).ext _)
rw [<- EType.cweaken_rename_comm]
rw [EType.weaken_rename]
rw [<- CaptureSet.cweaken_rename_comm]
rw [CaptureSet.weaken_rename]
trivial
case bindt ih =>
simp [Term.rename]
apply Typed.bindt
have ih := ih (ρ.text _)
simp [Term.rename, TBinding.rename, EType.rename, CType.rename] at ih
rw [EType.tweaken_rename] at ih
trivial
case bindc ih =>
simp [Term.rename]
apply Typed.bindc
have ih := ih (ρ.cext _)
simp [Term.rename, CBinding.rename] at ih
rw [EType.cweaken_rename_comm] at ih
rw [<- CaptureSet.cweaken_rename_comm]
trivial
case label =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply label
have h := ρ.lmap
aesop
case invoke ih1 ih2 =>
simp [Term.rename]
apply Typed.invoke
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih1
apply ih1; trivial
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih2
apply ih2; trivial
case boundary ih =>
simp [Term.rename, EType.rename, CType.rename]
apply Typed.boundary
have ih := ih ((ρ.cext _).ext _)
simp [CBinding.rename, FinFun.ext, CType.rename, SType.rename] at ih
rw
[ <- SType.cweaken_rename_comm
, SType.weaken_rename
, <- CaptureSet.cweaken_rename_comm
, CaptureSet.weaken_rename ]
simp [CBound.rename, EType.rename, CType.rename] at ih
exact ih | 4 | 111 | false | Type systems |
63 | Capless.Typed.subst | theorem Typed.subst
{Γ : Context n m k} {Δ : Context n' m k}
(h : Typed Γ t E Ct)
(σ : VarSubst Γ f Δ) :
Typed Δ (t.rename f) (E.rename f) (Ct.rename f) | capless-lean | Capless/Subst/Term/Typing.lean | [
"import Capless.Renaming.Capture.Typing",
"import Capless.Renaming.Term.Typing",
"import Capless.Renaming.Term.Subtyping",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Subst.Basic",
"import Capless.Subst.Term.Subcapturing",
"import Capless.Typing.Basic",
"import Capless.Renaming.Term.S... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
}
] | [
{
"name": "macro \"easy\" : tactic => `(tactic| assumption)",
"content": "macro \"easy\" : tactic => `(tactic| assumption)"
},
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:ma... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.crename",
"content": "theorem CSubtyp.crename\n (h : CSubtyp Γ C1 C2)\n (ρ : CVarMap Γ f Δ) :\n CSubtyp Δ (C1.crename f) (C2.crename f)"
},
{
"name": "SSubtyp.crename",
"content": "theorem SSubtyp.crename\n (h : SSubtyp Γ S1 S2)\n (ρ : CVarMap Γ f Δ) :\n SSubtyp Δ (S1.cr... | [] | [] | import Capless.Typing
import Capless.Subst.Basic
import Capless.Subst.Term.Subtyping
import Capless.Renaming.Term.Typing
namespace Capless | theorem Typed.subst
{Γ : Context n m k} {Δ : Context n' m k}
(h : Typed Γ t E Ct)
(σ : VarSubst Γ f Δ) :
Typed Δ (t.rename f) (E.rename f) (Ct.rename f) := | := by
induction h generalizing n'
case var hb =>
simp [Term.rename, EType.rename, CType.rename]
have hb1 := σ.map _ _ hb
simp [CType.rename] at hb1
apply Typed.precise_capture
trivial
case pack ih =>
simp [Term.rename, EType.rename]
apply pack
have ih := ih σ.cext
simp [EType.rename] at ih
exact ih
case sub hsc hs ih =>
apply sub
{ apply ih; trivial }
{ apply! hsc.subst }
{ apply! hs.subst }
case abs ih =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply abs
{ rw [CaptureSet.weaken_rename]
rw [<- CaptureSet.ext_rename_singleton_zero (f := f)]
apply ih
apply σ.ext }
case tabs ih =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply tabs
{ apply ih
apply σ.text }
case cabs ih =>
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply cabs
{ rw [<- CaptureSet.cweaken_rename_comm]
apply ih
apply σ.cext }
case app ih1 ih2 =>
simp [Term.rename]
rw [EType.rename_open]
apply app
{ have ih1 := ih1 σ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih1
exact ih1 }
{ have ih2 := ih2 σ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih2
exact ih2 }
case tapp ih =>
simp [Term.rename]
rw [EType.rename_topen]
apply tapp
have ih1 := ih σ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih1
exact ih1
case capp ih =>
simp [Term.rename]
rw [EType.rename_copen]
apply capp
have ih1 := ih σ
simp [Term.rename, EType.rename, CType.rename, SType.rename] at ih1
exact ih1
case letin ih1 ih2 =>
simp [Term.rename]
apply letin
{ have ih1 := ih1 σ
simp [EType.rename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.ext _)
rw [<- EType.weaken_rename] at ih2
rw [CaptureSet.weaken_rename]
exact ih2 }
case letex ih1 ih2 =>
simp [Term.rename]
apply letex
{ have ih1 := ih1 σ
simp [EType.rename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.cext.ext _)
rw [<- EType.weaken_rename] at ih2
rw [EType.cweaken_rename_comm] at ih2
rw [<- CaptureSet.cweaken_rename_comm]
rw [CaptureSet.weaken_rename]
exact ih2 }
case bindt ih =>
simp [Term.rename]
apply bindt
have ih := ih σ.text
rw [EType.tweaken_rename] at ih
simp [TBinding.rename] at ih
exact ih
case bindc ih =>
simp [Term.rename]
apply bindc
have ih := ih σ.cext
rw [EType.cweaken_rename_comm] at ih
simp [CBinding.rename] at ih
rw [<- CaptureSet.cweaken_rename_comm]
exact ih
case label hb =>
have hb1 := σ.lmap _ _ hb
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply label
aesop
case invoke ih1 ih2 =>
simp [Term.rename]
simp [EType.rename, CType.rename, SType.rename] at *
apply invoke
apply ih1; assumption
apply ih2; assumption
case boundary ih =>
simp [Term.rename]
simp [EType.rename, CType.rename, SType.rename] at *
apply boundary
have ih := ih (σ.cext.ext _)
simp
[ CBinding.rename
, EType.rename
, CType.rename
, SType.rename
, <- SType.weaken_rename
, SType.cweaken_rename_comm
, <- CaptureSet.weaken_rename
, CaptureSet.cweaken_rename_comm
, FinFun.ext ] at ih
exact ih | 5 | 190 | false | Type systems |
64 | Capless.Typed.csubst | theorem Typed.csubst
{Γ : Context n m k} {Δ : Context n m k'}
(h : Typed Γ t E Ct)
(σ : CVarSubst Γ f Δ) :
Typed Δ (t.crename f) (E.crename f) (Ct.crename f) | capless-lean | Capless/Subst/Capture/Typing.lean | [
"import Capless.Renaming.Capture.Typing",
"import Capless.Renaming.Term.Typing",
"import Capless.Renaming.Term.Subtyping",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Subst.Basic",
"import Capless.Renaming.Term.Subcapturing",
"import Capless.CaptureSet",
"import Capless.Subst.Capture.... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.crename",
"content": "theorem CSubtyp.crename\n (h : CSubtyp Γ C1 C2)\n (ρ : CVarMap Γ f Δ) :\n CSubtyp Δ (C1.crename f) (C2.crename f)"
},
{
"name": "SSubtyp.crename",
"content": "theorem SSubtyp.crename\n (h : SSubtyp Γ S1 S2)\n (ρ : CVarMap Γ f Δ) :\n SSubtyp Δ (S1.cr... | [] | [] | import Capless.Subst.Basic
import Capless.Subst.Capture.Subtyping
import Capless.Typing
namespace Capless | theorem Typed.csubst
{Γ : Context n m k} {Δ : Context n m k'}
(h : Typed Γ t E Ct)
(σ : CVarSubst Γ f Δ) :
Typed Δ (t.crename f) (E.crename f) (Ct.crename f) := | := by
induction h generalizing k'
case var hb =>
simp [Term.crename, EType.crename, CType.crename]
have hb1 := σ.map _ _ hb
simp [CType.crename] at hb1
apply Typed.var; trivial
case pack ih =>
simp [Term.crename, EType.crename]
apply pack
have ih := ih σ.cext
simp [EType.crename] at ih
exact ih
case sub hsc hs ih =>
apply sub
{ apply ih; trivial }
{ apply! hsc.csubst }
{ apply! hs.csubst }
case abs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply abs
{ rw [CaptureSet.weaken_crename]
apply ih
apply σ.ext }
case tabs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply tabs
{ apply ih
apply σ.text }
case cabs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply cabs
{ rw [CaptureSet.cweaken_crename]
apply ih
apply σ.cext }
case app ih1 ih2 =>
simp [Term.crename]
rw [EType.crename_open]
apply app
{ have ih1 := ih1 σ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1 }
{ have ih2 := ih2 σ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih2
exact ih2 }
case tapp ih =>
simp [Term.crename]
rw [EType.crename_topen]
apply tapp
have ih1 := ih σ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1
case capp ih =>
simp [Term.crename]
rw [EType.crename_copen]
apply capp
have ih1 := ih σ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1
case letin ih1 ih2 =>
simp [Term.crename]
apply letin
{ have ih1 := ih1 σ
simp [EType.crename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.ext _)
rw [<- EType.weaken_crename] at ih2
rw [CaptureSet.weaken_crename]
exact ih2 }
case letex ih1 ih2 =>
simp [Term.crename]
apply letex
{ have ih1 := ih1 σ
simp [EType.crename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.cext.ext _)
rw [<- EType.weaken_crename] at ih2
rw [<- EType.cweaken_crename] at ih2
rw [CaptureSet.cweaken_crename]
rw [CaptureSet.weaken_crename]
exact ih2 }
case bindt ih =>
simp [Term.crename]
apply bindt
have ih := ih σ.text
rw [<- EType.tweaken_crename] at ih
simp [TBinding.crename] at ih
exact ih
case bindc ih =>
simp [Term.crename]
apply bindc
have ih := ih σ.cext
rw [<- EType.cweaken_crename] at ih
rw [CaptureSet.cweaken_crename]
trivial
case label =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply label
have h := σ.lmap
aesop
case invoke ih1 ih2 =>
simp [Term.crename]
simp [EType.crename, CType.crename, SType.crename] at ih1 ih2
apply invoke
apply ih1; assumption
apply ih2; assumption
case boundary ih =>
simp [Term.crename]
simp [EType.crename, CType.crename, SType.crename]
apply boundary
have ih := ih (σ.cext.ext _)
simp [CBinding.crename, EType.crename, CType.crename, SType.crename, FinFun.ext] at ih
rw [ <- SType.cweaken_crename
, <- SType.weaken_crename
, <- SType.cweaken_crename
, <- CaptureSet.weaken_crename
, <- CaptureSet.cweaken_crename ] at ih
aesop | 5 | 195 | false | Type systems |
65 | Capless.Typed.crename | theorem Typed.crename
{Γ : Context n m k} {Δ : Context n m k'}
(h : Typed Γ t E Ct)
(ρ : CVarMap Γ f Δ) :
Typed Δ (t.crename f) (E.crename f) (Ct.crename f) | capless-lean | Capless/Renaming/Capture/Typing.lean | [
"import Capless.Typing",
"import Capless.Renaming.Capture.Subtyping",
"import Capless.Type.Basic",
"import Capless.CaptureSet",
"import Capless.Renaming.Capture.Subcapturing",
"import Capless.Renaming.Basic"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "SType.cweaken_crename",
"content": "theorem SType.cweaken_crename {S : SType n m k} :\n (S.crename f).cweaken = S.cweaken.crename f.ext"
},
{
"name": "SType.crename_crename",
"content": "theorem SType.crename_crename (S : SType n m k) (f : FinFun k k') (g : FinFun k' k'') :\n (S.cre... | [] | [] | import Capless.Typing
import Capless.Renaming.Basic
import Capless.Renaming.Capture.Subtyping
namespace Capless | theorem Typed.crename
{Γ : Context n m k} {Δ : Context n m k'}
(h : Typed Γ t E Ct)
(ρ : CVarMap Γ f Δ) :
Typed Δ (t.crename f) (E.crename f) (Ct.crename f) := | := by
induction h generalizing k'
case var hb =>
simp [Term.crename, EType.crename, CType.crename]
apply var
have hb1 := ρ.map _ _ hb
simp [CType.crename] at hb1
exact hb1
case pack ih =>
simp [Term.crename, EType.crename]
apply pack
have ih := ih (ρ.cext _)
simp [Term.crename, EType.crename] at ih
exact ih
case sub hsc hsub ih =>
apply sub
apply ih ρ
apply! hsc.crename
apply! ESubtyp.crename hsub
case abs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply abs
rw [CaptureSet.weaken_crename]
apply ih
apply ρ.ext
case tabs hc ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply tabs
apply ih
apply ρ.text
case cabs hc ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply cabs
rw [CaptureSet.cweaken_crename]
apply ih
apply ρ.cext
case app ih1 ih2 =>
simp [Term.crename, EType.crename_open]
apply app
have ih1 := ih1 ρ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1
have ih2 := ih2 ρ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih2
exact ih2
case tapp ih1 =>
simp [Term.crename, EType.crename_topen]
apply tapp
have ih1 := ih1 ρ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1
case capp ih1 =>
simp [Term.crename, EType.crename_copen]
apply capp
have ih1 := ih1 ρ
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
exact ih1
case letin ih1 ih2 =>
simp [Term.crename]
apply letin
have ih1 := ih1 ρ
simp [EType.crename] at ih1
exact ih1
have ih2 := ih2 (ρ.ext _)
rw [<- EType.weaken_crename] at ih2
rw [CaptureSet.weaken_crename]
exact ih2
case letex ih1 ih2 =>
simp [Term.crename]
apply letex
have ih1 := ih1 ρ
simp [EType.crename] at ih1
exact ih1
have ih2 := ih2 ((ρ.cext _).ext _)
rw [EType.cweaken_crename]
rw [EType.weaken_crename]
rw [CaptureSet.cweaken_crename, CaptureSet.weaken_crename]
exact ih2
case bindt ih =>
simp [Term.crename]
apply bindt
have ih := ih (ρ.text _)
rw [<- EType.tweaken_crename] at ih
exact ih
case bindc ih =>
simp [Term.crename]
apply bindc
have ih := ih (ρ.cext _)
rw [<- EType.cweaken_crename] at ih
rw [CaptureSet.cweaken_crename]
exact ih
case label =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply label
have h := ρ.lmap
aesop
case invoke ih1 ih2 =>
simp [Term.crename]
apply invoke
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih1
apply ih1; assumption
simp [Term.crename, EType.crename, CType.crename, SType.crename] at ih2
apply ih2; assumption
case boundary ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply boundary
have ih := ih ((ρ.cext _).ext _)
simp [CBinding.crename,
TBinding.crename,
CType.crename, EType.crename,
FinFun.ext,
SType.crename] at ih
rw [<- SType.cweaken_crename,
<- SType.weaken_crename,
<- SType.cweaken_crename,
<- CaptureSet.weaken_crename,
<- CaptureSet.cweaken_crename] at ih
exact ih | 3 | 119 | false | Type systems |
66 | Capless.Typed.trename | theorem Typed.trename
{Γ : Context n m k} {Δ : Context n m' k}
(h : Typed Γ t E Ct)
(ρ : TVarMap Γ f Δ) :
Typed Δ (t.trename f) (E.trename f) Ct | capless-lean | Capless/Renaming/Type/Typing.lean | [
"import Capless.Renaming.Type.Subtyping",
"import Capless.Typing",
"import Capless.Type.Basic",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Renaming.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "EType.trename_topen",
"content": "theorem EType.trename_topen {E : EType n (m+1) k} :\n (E.topen X).trename f = (E.trename f.ext).topen (f X)"
},
{
"name": "EType.trename_trename",
"content": "theorem EType.trename_trename (E : EType n m k) (f : FinFun m m') (g : FinFun m' m'') :\n ... | [] | [] | import Capless.Typing
import Capless.Renaming.Basic
import Capless.Renaming.Type.Subtyping
namespace Capless | theorem Typed.trename
{Γ : Context n m k} {Δ : Context n m' k}
(h : Typed Γ t E Ct)
(ρ : TVarMap Γ f Δ) :
Typed Δ (t.trename f) (E.trename f) Ct := | := by
induction h generalizing m'
case var =>
simp [Term.trename, EType.trename, CType.trename]
apply var
rename_i hb
have hb1 := ρ.map _ _ hb
simp [CType.trename] at hb1
trivial
case pack ih =>
simp [Term.trename, EType.trename]
apply pack
have ih := ih (ρ.cext _)
simp [Term.trename, EType.trename] at ih
trivial
case sub hsc hs ih =>
apply sub
aesop
apply! hsc.trename
apply! ESubtyp.trename
case abs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply abs
apply? ih
apply! TVarMap.ext
case app ih1 ih2 =>
simp [Term.trename]
rw [EType.trename_open]
apply app
have ih1 := ih1 ρ
simp [EType.trename, CType.trename, SType.trename, Term.trename] at ih1
trivial
have ih2 := ih2 ρ
simp [Term.trename, EType.trename] at ih2
trivial
case tabs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply tabs
apply? ih
apply! TVarMap.text
case cabs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply cabs
have ih1 := ih (ρ.cext _)
trivial
case tapp ih =>
simp [Term.trename]
rw [EType.trename_topen]
apply tapp
have ih := ih ρ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih
trivial
case capp ih =>
simp [Term.trename]
rw [EType.trename_copen]
apply capp
have ih := ih ρ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih
trivial
case letin ih1 ih2 =>
simp [Term.trename]
apply letin
simp [EType.trename] at ih1
aesop
have ih2 := ih2 (ρ.ext _)
rw [<- EType.weaken_trename] at ih2
trivial
case letex ih1 ih2 =>
simp [Term.trename]
apply letex
simp [EType.trename] at ih1
aesop
have ih2 := ih2 ((ρ.cext _).ext _)
rw [<- EType.weaken_trename] at ih2
rw [<- EType.cweaken_trename] at ih2
trivial
case bindt ih =>
simp [Term.trename]
apply bindt
have ih := ih (ρ.text _)
rw [EType.tweaken_trename]
trivial
case bindc ih =>
simp [Term.trename]
apply bindc
have ih := ih (ρ.cext _)
rw [EType.cweaken_trename]
trivial
case label =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply label
have h := ρ.lmap
aesop
case invoke ih1 ih2 =>
simp [Term.trename]
apply invoke
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih1
apply ih1; trivial
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih2
apply ih2; trivial
case boundary ih =>
simp [Term.trename, EType.trename, CType.trename]
apply boundary
have ih := ih ((ρ.cext _).ext _)
simp [FinFun.ext, CType.trename, SType.trename] at ih
rw [ SType.cweaken_trename
, SType.weaken_trename ]
simp [EType.trename, CType.trename] at ih
exact ih | 3 | 111 | false | Type systems |
67 | Capless.Typed.tsubst | theorem Typed.tsubst
{Γ : Context n m k} {Δ : Context n m' k}
(h : Typed Γ t E Ct)
(σ : TVarSubst Γ f Δ) :
Typed Δ (t.trename f) (E.trename f) Ct | capless-lean | Capless/Subst/Type/Typing.lean | [
"import Capless.Renaming.Type.Subtyping",
"import Capless.Renaming.Term.Typing",
"import Capless.Typing",
"import Capless.Renaming.Type.Typing",
"import Capless.Renaming.Capture.Typing",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Renaming.Term.Subtyping",
"import Capless.Subst.Type.S... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "macro \"easy\" : tactic => `(tactic| assumption)",
"content": "macro \"easy\" : tactic => `(tactic| assumption)"
},
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notatio... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.crename",
"content": "theorem CSubtyp.crename\n (h : CSubtyp Γ C1 C2)\n (ρ : CVarMap Γ f Δ) :\n CSubtyp Δ (C1.crename f) (C2.crename f)"
},
{
"name": "SSubtyp.crename",
"content": "theorem SSubtyp.crename\n (h : SSubtyp Γ S1 S2)\n (ρ : CVarMap Γ f Δ) :\n SSubtyp Δ (S1.cr... | [] | [] | import Capless.Subst.Basic
import Capless.Subst.Type.Subtyping
import Capless.Typing
namespace Capless | theorem Typed.tsubst
{Γ : Context n m k} {Δ : Context n m' k}
(h : Typed Γ t E Ct)
(σ : TVarSubst Γ f Δ) :
Typed Δ (t.trename f) (E.trename f) Ct := | := by
induction h generalizing m'
case var hb =>
simp [Term.trename, EType.trename, CType.trename]
have hb1 := σ.map _ _ hb
simp [CType.trename] at hb1
apply Typed.var; trivial
case pack ih =>
simp [Term.trename, EType.trename]
apply pack
have ih := ih σ.cext
simp [EType.trename] at ih
exact ih
case sub hsc hs ih =>
apply sub
{ apply ih; trivial }
{ apply! hsc.tsubst }
{ apply! hs.tsubst }
case abs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply abs
{ apply ih
apply σ.ext }
case tabs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply tabs
{ apply ih
apply σ.text }
case cabs ih =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
apply cabs
{ apply ih
apply σ.cext }
case app ih1 ih2 =>
simp [Term.trename]
rw [EType.trename_open]
apply app
{ have ih1 := ih1 σ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih1
exact ih1 }
{ have ih2 := ih2 σ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih2
exact ih2 }
case tapp ih =>
simp [Term.trename]
rw [EType.trename_topen]
apply tapp
have ih1 := ih σ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih1
exact ih1
case capp ih =>
simp [Term.trename]
rw [EType.trename_copen]
apply capp
have ih1 := ih σ
simp [Term.trename, EType.trename, CType.trename, SType.trename] at ih1
exact ih1
case letin ih1 ih2 =>
simp [Term.trename]
apply letin
{ have ih1 := ih1 σ
simp [EType.trename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.ext _)
rw [<- EType.weaken_trename] at ih2
exact ih2 }
case letex ih1 ih2 =>
simp [Term.trename]
apply letex
{ have ih1 := ih1 σ
simp [EType.trename] at ih1
exact ih1 }
{ have ih2 := ih2 (σ.cext.ext _)
rw [<-EType.weaken_trename] at ih2
rw [<-EType.cweaken_trename] at ih2
exact ih2 }
case bindt ih =>
simp [Term.trename]
apply bindt
have ih := ih (σ.text _)
rw [<-EType.tweaken_trename] at ih
simp [TBinding.trename] at ih
exact ih
case bindc ih =>
simp [Term.trename]
apply bindc
have ih := ih σ.cext
rw [<-EType.cweaken_trename] at ih
trivial
case label hb =>
simp [Term.trename, EType.trename, CType.trename, SType.trename]
have hb1 := σ.lmap _ _ hb
apply label; assumption
case invoke ih1 ih2 =>
simp [Term.trename]
simp [EType.trename, CType.trename, SType.trename] at ih1 ih2
apply invoke
apply ih1; assumption
apply ih2; assumption
case boundary ih =>
simp [Term.trename]
simp [EType.trename, CType.trename, SType.trename]
apply boundary
have ih := ih (σ.cext.ext _)
simp [EType.trename, CType.trename, SType.trename] at ih
rw [ <- SType.cweaken_trename
, <- SType.weaken_trename
, <- SType.cweaken_trename ] at ih
aesop | 5 | 189 | false | Type systems |
68 | Capless.SSubtyp.rename | theorem SSubtyp.rename
(h : SSubtyp Γ S1 S2)
(ρ : VarMap Γ f Δ) :
SSubtyp Δ (S1.rename f) (S2.rename f) | capless-lean | Capless/Renaming/Term/Subtyping.lean | [
"import Capless.Renaming.Term.Subcapturing",
"import Capless.Subtyping",
"import Capless.Renaming.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Subcapt.rename",
"content": "theorem Subcapt.rename\n (h : Subcapt Γ C1 C2)\n (ρ : VarMap Γ f Δ) :\n Subcapt Δ (C1.rename f) (C2.rename f)"
},
{
"name": "CaptureSet.Subset.rename",
"content": "theorem CaptureSet.Subset.rename {C1 C2 : CaptureSet n k}\n (h : C1 ⊆ C2) :\n C1.rename... | [
{
"name": "Capless.SSubtyp.rename_motive1",
"content": "def SSubtyp.rename_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarMap Γ f Δ),\n ESubtyp Δ (E1.rename f) (E2.rename f)"
},
{
"name": "Capless.SSub... | [
{
"name": "Capless.Subbound.rename",
"content": "theorem Subbound.rename\n (h : Subbound Γ B1 B2)\n (ρ : VarMap Γ f Δ) :\n Subbound Δ (B1.rename f) (B2.rename f)"
}
] | import Capless.Subtyping
import Capless.Renaming.Basic
import Capless.Renaming.Term.Subcapturing
namespace Capless
def SSubtyp.rename_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarMap Γ f Δ),
ESubtyp Δ (E1.rename f) (E2.rename f)
def SSubtyp.rename_motive2
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarMap Γ f Δ),
CSubtyp Δ (C1.rename f) (C2.rename f)
def SSubtyp.rename_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarMap Γ f Δ),
SSubtyp Δ (S1.rename f) (S2.rename f) | theorem SSubtyp.rename
(h : SSubtyp Γ S1 S2)
(ρ : VarMap Γ f Δ) :
SSubtyp Δ (S1.rename f) (S2.rename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.rename_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.rename_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.rename_motive3 Γ S1 S2)
(t := h) (ρ := ρ)
case exist ih =>
unfold SSubtyp.rename_motive1 SSubtyp.rename_motive2
intros; intros
simp [EType.rename]
apply ESubtyp.exist
rename_i ih _ _ _ _
apply ih; try assumption
apply VarMap.cext; trivial
case type ih =>
unfold rename_motive1 rename_motive2
repeat intro
simp [EType.rename]
apply ESubtyp.type
aesop
case capt =>
unfold rename_motive2 rename_motive3
repeat intro
simp [CType.rename]
apply CSubtyp.capt
apply Subcapt.rename <;> assumption
aesop
case top =>
unfold rename_motive3
repeat intro
simp [SType.rename]
constructor
case refl =>
unfold rename_motive3
repeat intro
constructor
case trans =>
unfold rename_motive3
repeat intro
rename_i ih1 ih2 _ _ _ _
apply trans <;> aesop
case tvar =>
unfold rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.tvar
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.rename] at hb1
assumption
case tinstl =>
unfold rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.tinstl
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.rename] at hb1
assumption
case tinstr =>
unfold rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.tinstr
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.rename] at hb1
assumption
case boxed =>
unfold rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.boxed
aesop
case label =>
unfold rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.label
aesop
case xforall =>
unfold rename_motive3 rename_motive1
repeat intro
simp [SType.rename]
apply SSubtyp.xforall
aesop
rename_i ih _ _ _ _
apply ih; try assumption
apply VarMap.ext; trivial
case cforall =>
unfold rename_motive1 rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.cforall
{ apply Subbound.rename <;> easy }
{ rename_i ih _ _ _ _
apply ih
apply VarMap.cext; trivial }
case tforall =>
unfold rename_motive1 rename_motive3
repeat intro
simp [SType.rename]
apply SSubtyp.tforall
aesop
rename_i ih1 ih2 _ _ _ _
apply ih2; try assumption
apply VarMap.text; trivial | 4 | 49 | false | Type systems |
69 | Capless.SSubtyp.subst | theorem SSubtyp.subst
(h : SSubtyp Γ S1 S2)
(σ : VarSubst Γ f Δ) :
SSubtyp Δ (S1.rename f) (S2.rename f) | capless-lean | Capless/Subst/Term/Subtyping.lean | [
"import Capless.Subst.Term.Subcapturing",
"import Capless.Renaming.Term.Subtyping",
"import Capless.Renaming.Term.Typing",
"import Capless.Renaming.Term.Subcapturing",
"import Capless.Subtyping",
"import Capless.Subst.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
}
] | [
{
"name": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t",
"content": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t"
},
{
"name": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u",
"content": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u"
},
{
"name": "notat... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.rename",
"content": "theorem CSubtyp.rename\n (h : CSubtyp Γ T1 T2)\n (ρ : VarMap Γ f Δ) :\n CSubtyp Δ (T1.rename f) (T2.rename f)"
},
{
"name": "SSubtyp.rename",
"content": "theorem SSubtyp.rename\n (h : SSubtyp Γ S1 S2)\n (ρ : VarMap Γ f Δ) :\n SSubtyp Δ (S1.rename f) ... | [
{
"name": "Capless.SSubtyp.subst_motive1",
"content": "def SSubtyp.subst_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarSubst Γ f Δ),\n ESubtyp Δ (E1.rename f) (E2.rename f)"
},
{
"name": "Capless.SSub... | [
{
"name": "Capless.Subbound.subst",
"content": "theorem Subbound.subst\n (h : Subbound Γ B1 B2)\n (σ : VarSubst Γ f Δ) :\n Subbound Δ (B1.rename f) (B2.rename f)"
}
] | import Capless.Subst.Basic
import Capless.Subtyping
import Capless.Subst.Term.Subcapturing
namespace Capless
def SSubtyp.subst_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarSubst Γ f Δ),
ESubtyp Δ (E1.rename f) (E2.rename f)
def SSubtyp.subst_motive2
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarSubst Γ f Δ),
CSubtyp Δ (C1.rename f) (C2.rename f)
def SSubtyp.subst_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {n'} (f : FinFun n n') (Δ : Context n' m k) (ρ : VarSubst Γ f Δ),
SSubtyp Δ (S1.rename f) (S2.rename f) | theorem SSubtyp.subst
(h : SSubtyp Γ S1 S2)
(σ : VarSubst Γ f Δ) :
SSubtyp Δ (S1.rename f) (S2.rename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.subst_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.subst_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.subst_motive3 Γ S1 S2)
(t := h) (ρ := σ)
case exist =>
unfold subst_motive1 subst_motive2
repeat intro
simp [EType.rename]
apply ESubtyp.exist
rename_i ih _ _ _ _
apply ih
apply VarSubst.cext; trivial
case type =>
unfold subst_motive1 subst_motive2
repeat intro
simp [EType.rename]
apply ESubtyp.type
aesop
case capt =>
unfold subst_motive2 subst_motive3
repeat intro
simp [CType.rename]
apply CSubtyp.capt
apply Subcapt.subst <;> trivial
aesop
case top =>
unfold subst_motive3
repeat intro
simp [SType.rename]
apply top
case refl =>
unfold subst_motive3
repeat intro
apply refl
case trans =>
unfold subst_motive3
repeat intro
apply trans
{ aesop }
{ aesop }
case tvar =>
unfold subst_motive3
repeat intro
simp [SType.rename]
apply tvar
rename_i hb _ _ _ σ
have hb1 := σ.tmap _ _ hb
simp [TBinding.rename] at hb1
exact hb1
case tinstl =>
unfold subst_motive3
repeat intro
simp [SType.rename]
apply tinstl
rename_i hb _ _ _ σ
have hb1 := σ.tmap _ _ hb
simp [TBinding.rename] at hb1
exact hb1
case tinstr =>
unfold subst_motive3
repeat intro
simp [SType.rename]
apply tinstr
rename_i hb _ _ _ σ
have hb1 := σ.tmap _ _ hb
simp [TBinding.rename] at hb1
exact hb1
case boxed =>
unfold subst_motive2 subst_motive3
repeat intro
simp [SType.rename]
apply boxed
aesop
case label =>
unfold subst_motive3
repeat intro
simp
apply label
aesop
case xforall =>
unfold subst_motive1 subst_motive2 subst_motive3
repeat intro
simp [SType.rename]
apply xforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih
apply VarSubst.ext; trivial }
case tforall =>
unfold subst_motive1 subst_motive3
repeat intro
simp [SType.rename]
apply tforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih
apply VarSubst.text; trivial }
case cforall =>
unfold subst_motive1 subst_motive3
repeat intro
simp [SType.rename]
apply cforall
{ apply Subbound.subst <;> easy }
{ rename_i ih _ _ _ σ
apply ih
apply VarSubst.cext; trivial } | 6 | 122 | false | Type systems |
70 | Capless.SSubtyp.csubst | theorem SSubtyp.csubst
(h : SSubtyp Γ S1 S2)
(σ : CVarSubst Γ f Δ) :
SSubtyp Δ (S1.crename f) (S2.crename f) | capless-lean | Capless/Subst/Capture/Subtyping.lean | [
"import Capless.Renaming.Capture.Typing",
"import Capless.Subst.Basic",
"import Capless.Renaming.Capture.Subtyping",
"import Capless.Subst.Capture.Subcapturing",
"import Capless.Context",
"import Capless.Subtyping",
"import Capless.Renaming.Capture.Subcapturing"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.crename",
"content": "theorem CSubtyp.crename\n (h : CSubtyp Γ C1 C2)\n (ρ : CVarMap Γ f Δ) :\n CSubtyp Δ (C1.crename f) (C2.crename f)"
},
{
"name": "SSubtyp.crename",
"content": "theorem SSubtyp.crename\n (h : SSubtyp Γ S1 S2)\n (ρ : CVarMap Γ f Δ) :\n SSubtyp Δ (S1.cr... | [
{
"name": "Capless.SSubtyp.csubst_motive1",
"content": "def SSubtyp.csubst_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarSubst Γ f Δ),\n ESubtyp Δ (E1.crename f) (E2.crename f)"
},
{
"name": "Capless... | [
{
"name": "Capless.Subbound.csubst",
"content": "theorem Subbound.csubst\n (h : Subbound Γ B1 B2)\n (σ : CVarSubst Γ f Δ) :\n Subbound Δ (B1.crename f) (B2.crename f)"
}
] | import Capless.Subtyping
import Capless.Subst.Basic
import Capless.Subst.Capture.Subcapturing
namespace Capless
def SSubtyp.csubst_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarSubst Γ f Δ),
ESubtyp Δ (E1.crename f) (E2.crename f)
def SSubtyp.csubst_motive2
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarSubst Γ f Δ),
CSubtyp Δ (C1.crename f) (C2.crename f)
def SSubtyp.csubst_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarSubst Γ f Δ),
SSubtyp Δ (S1.crename f) (S2.crename f) | theorem SSubtyp.csubst
(h : SSubtyp Γ S1 S2)
(σ : CVarSubst Γ f Δ) :
SSubtyp Δ (S1.crename f) (S2.crename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 _ => SSubtyp.csubst_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 _ => SSubtyp.csubst_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 _ => SSubtyp.csubst_motive3 Γ S1 S2)
(t := h) (ρ := σ)
case exist =>
unfold csubst_motive1 csubst_motive2
repeat intro
simp [EType.crename]
apply ESubtyp.exist
rename_i ih _ _ _ ρ
apply ih ; try assumption
apply CVarSubst.cext; trivial
case type =>
unfold csubst_motive1 csubst_motive2
repeat intro
simp [EType.crename]
apply ESubtyp.type
aesop
case capt =>
unfold csubst_motive2 csubst_motive3
repeat intro
simp [CType.crename]
apply CSubtyp.capt
apply Subcapt.csubst <;> trivial
aesop
case top =>
unfold csubst_motive3
repeat intro
simp [SType.crename]
apply top
case refl =>
unfold csubst_motive3
repeat intro
apply refl
case trans =>
unfold csubst_motive3
repeat intro
apply trans
{ aesop }
{ aesop }
case tvar =>
unfold csubst_motive3
repeat intro
rename_i hb _ _ _ σ
have hb1 := σ.tmap _ _ hb
simp [SType.crename]
apply tvar
trivial
case tinstl =>
unfold csubst_motive3
repeat intro
rename_i hb _ _ Δ σ
have hb1 := σ.tmap _ _ hb
simp [SType.crename]
apply SSubtyp.tinstl
trivial
case tinstr =>
unfold csubst_motive3
repeat intro
rename_i hb _ _ Δ σ
have hb1 := σ.tmap _ _ hb
simp [SType.crename]
apply SSubtyp.tinstr
trivial
case boxed =>
unfold csubst_motive2 csubst_motive3
repeat intro
simp [SType.crename]
apply boxed
aesop
case label =>
unfold csubst_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.label
aesop
case xforall =>
unfold csubst_motive1 csubst_motive2 csubst_motive3
repeat intro
simp [SType.crename]
apply xforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
apply CVarSubst.ext; trivial }
case tforall =>
unfold csubst_motive1 csubst_motive3
repeat intro
simp [SType.crename]
apply tforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
rw [<-TBinding.crename_bound]
apply CVarSubst.text; trivial }
case cforall =>
unfold csubst_motive1 csubst_motive3
repeat intro
simp [SType.crename]
apply cforall
{ apply Subbound.csubst <;> easy }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
apply CVarSubst.cext; trivial
} | 6 | 112 | false | Type systems |
71 | Capless.SSubtyp.crename | theorem SSubtyp.crename
(h : SSubtyp Γ S1 S2)
(ρ : CVarMap Γ f Δ) :
SSubtyp Δ (S1.crename f) (S2.crename f) | capless-lean | Capless/Renaming/Capture/Subtyping.lean | [
"import Capless.Tactics",
"import Capless.Subtyping",
"import Capless.Renaming.Capture.Subcapturing",
"import Capless.Renaming.Basic"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Subcapt.crename",
"content": "theorem Subcapt.crename\n (h : Subcapt Γ C1 C2)\n (ρ : CVarMap Γ f Δ) :\n Subcapt Δ (C1.crename f) (C2.crename f)"
},
{
"name": "CaptureSet.Subset.crename",
"content": "theorem CaptureSet.Subset.crename {C1 C2 : CaptureSet n k}\n (h : C1 ⊆ C2) :\n C1... | [
{
"name": "Capless.SSubtyp.crename_motive1",
"content": "def SSubtyp.crename_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarMap Γ f Δ),\n ESubtyp Δ (E1.crename f) (E2.crename f)"
},
{
"name": "Capless... | [
{
"name": "Capless.Subbound.crename",
"content": "theorem Subbound.crename\n (h : Subbound Γ B1 B2)\n (ρ : CVarMap Γ f Δ) :\n Subbound Δ (B1.crename f) (B2.crename f)"
}
] | import Capless.Tactics
import Capless.Subtyping
import Capless.Renaming.Basic
import Capless.Renaming.Capture.Subcapturing
namespace Capless
def SSubtyp.crename_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarMap Γ f Δ),
ESubtyp Δ (E1.crename f) (E2.crename f)
def SSubtyp.crename_motive2
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarMap Γ f Δ),
CSubtyp Δ (C1.crename f) (C2.crename f)
def SSubtyp.crename_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {k'} (f : FinFun k k') (Δ : Context n m k') (ρ : CVarMap Γ f Δ),
SSubtyp Δ (S1.crename f) (S2.crename f) | theorem SSubtyp.crename
(h : SSubtyp Γ S1 S2)
(ρ : CVarMap Γ f Δ) :
SSubtyp Δ (S1.crename f) (S2.crename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.crename_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.crename_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.crename_motive3 Γ S1 S2)
(t := h) (ρ := ρ)
case exist =>
unfold SSubtyp.crename_motive1 SSubtyp.crename_motive2
repeat intro
simp [EType.crename]
apply ESubtyp.exist
rename_i ih _ _ _ _
apply ih; try assumption
apply CVarMap.cext; trivial
case type =>
unfold crename_motive2 crename_motive1
repeat intro
simp [EType.crename]
apply ESubtyp.type
aesop
case capt =>
unfold crename_motive3 crename_motive2
repeat intro
simp [CType.crename]
apply CSubtyp.capt
apply Subcapt.crename <;> aesop
aesop
case top =>
unfold crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.top
case refl =>
unfold crename_motive3
repeat intro
constructor
case trans =>
unfold crename_motive3
repeat intro
apply SSubtyp.trans
aesop
aesop
case tvar =>
unfold crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.tvar
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.crename] at hb1
trivial
case tinstl =>
unfold crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.tinstl
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.crename] at hb1
assumption
case tinstr =>
unfold crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.tinstr
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.crename] at hb1
assumption
case boxed =>
unfold crename_motive3 crename_motive2
repeat intro
simp [SType.crename]
apply SSubtyp.boxed
aesop
case label =>
unfold crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.label
aesop
case xforall =>
unfold crename_motive1 crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.xforall
aesop
rename_i ih _ _ _ _
apply ih; try assumption
apply CVarMap.ext; trivial
case tforall =>
unfold crename_motive1 crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.tforall
aesop
rename_i ih1 ih2 _ _ _ _
apply ih2; try easy
apply CVarMap.text; easy
case cforall =>
unfold crename_motive1 crename_motive3
repeat intro
simp [SType.crename]
apply SSubtyp.cforall
{ apply Subbound.crename <;> easy }
{ rename_i ih _ _ _ _
apply ih
apply CVarMap.cext; easy } | 6 | 60 | false | Type systems |
72 | Capless.SSubtyp.tsubst | theorem SSubtyp.tsubst
(h : SSubtyp Γ S1 S2)
(σ : TVarSubst Γ f Δ) :
SSubtyp Δ (S1.trename f) (S2.trename f) | capless-lean | Capless/Subst/Type/Subtyping.lean | [
"import Capless.Renaming.Type.Subtyping",
"import Capless.Renaming.Type.Typing",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Subst.Type.Subcapturing",
"import Capless.Subtyping",
"import Capless.Subst.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.trename",
"content": "theorem CSubtyp.trename\n (h : CSubtyp Γ T1 T2)\n (ρ : TVarMap Γ f Δ) :\n CSubtyp Δ (T1.trename f) (T2.trename f)"
},
{
"name": "SSubtyp.trename",
"content": "theorem SSubtyp.trename\n (h : SSubtyp Γ S1 S2)\n (ρ : TVarMap Γ f Δ) :\n SSubtyp Δ (S1.tr... | [
{
"name": "Capless.SSubtyp.tsubst_motive1",
"content": "def SSubtyp.tsubst_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarSubst Γ f Δ),\n ESubtyp Δ (E1.trename f) (E2.trename f)"
},
{
"name": "Capless... | [
{
"name": "Capless.Subbound.tsubst",
"content": "theorem Subbound.tsubst\n (h : Subbound Γ B1 B2)\n (σ : TVarSubst Γ f Δ) :\n Subbound Δ B1 B2"
}
] | import Capless.Subst.Basic
import Capless.Subtyping
import Capless.Subst.Type.Subcapturing
namespace Capless
def SSubtyp.tsubst_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarSubst Γ f Δ),
ESubtyp Δ (E1.trename f) (E2.trename f)
def SSubtyp.tsubst_motive2
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarSubst Γ f Δ),
CSubtyp Δ (C1.trename f) (C2.trename f)
def SSubtyp.tsubst_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarSubst Γ f Δ),
SSubtyp Δ (S1.trename f) (S2.trename f) | theorem SSubtyp.tsubst
(h : SSubtyp Γ S1 S2)
(σ : TVarSubst Γ f Δ) :
SSubtyp Δ (S1.trename f) (S2.trename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 _ => SSubtyp.tsubst_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 _ => SSubtyp.tsubst_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 _ => SSubtyp.tsubst_motive3 Γ S1 S2)
(t := h) (ρ := σ)
case exist =>
unfold tsubst_motive1 tsubst_motive2
repeat intro
simp [EType.trename]
apply ESubtyp.exist
rename_i ih _ _ _ ρ
apply ih ; try assumption
apply TVarSubst.cext; trivial
case type =>
unfold tsubst_motive1 tsubst_motive2
repeat intro
simp [EType.trename]
apply ESubtyp.type
aesop
case capt =>
unfold tsubst_motive2 tsubst_motive3
repeat intro
simp [CType.trename]
apply CSubtyp.capt
apply Subcapt.tsubst <;> trivial
aesop
case top =>
unfold tsubst_motive3
repeat intro
simp [SType.trename]
apply top
case refl =>
unfold tsubst_motive3
repeat intro
apply refl
case trans =>
unfold tsubst_motive3
repeat intro
apply trans
{ aesop }
{ aesop }
case tvar =>
unfold tsubst_motive3
repeat intro
rename_i hb _ _ _ σ
have hb1 := σ.tmap _ _ hb
simp [SType.trename]
trivial
case tinstl =>
unfold tsubst_motive3
repeat intro
rename_i hb _ _ Δ σ
have hb1 := σ.tmap_inst _ _ hb
simp [SType.trename]
apply SSubtyp.tinstl
trivial
case tinstr =>
unfold tsubst_motive3
repeat intro
rename_i hb _ _ Δ σ
have hb1 := σ.tmap_inst _ _ hb
simp [SType.trename]
apply SSubtyp.tinstr
trivial
case boxed =>
unfold tsubst_motive2 tsubst_motive3
repeat intro
simp [SType.trename]
apply boxed
aesop
case label =>
unfold tsubst_motive3
repeat intro
simp [SType.trename]
apply label
aesop
case xforall =>
unfold tsubst_motive1 tsubst_motive2 tsubst_motive3
repeat intro
simp [SType.trename]
apply xforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
apply TVarSubst.ext; trivial }
case tforall =>
unfold tsubst_motive1 tsubst_motive3
repeat intro
simp [SType.trename]
apply tforall
{ aesop }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
apply TVarSubst.text; trivial }
case cforall =>
unfold tsubst_motive1 tsubst_motive3
repeat intro
simp [SType.trename]
apply cforall
{ apply Subbound.tsubst <;> easy }
{ rename_i ih _ _ _ σ
apply ih ; try assumption
apply TVarSubst.cext; trivial } | 5 | 121 | false | Type systems |
73 | Capless.SSubtyp.trename | theorem SSubtyp.trename
(h : SSubtyp Γ S1 S2)
(ρ : TVarMap Γ f Δ) :
SSubtyp Δ (S1.trename f) (S2.trename f) | capless-lean | Capless/Renaming/Type/Subtyping.lean | [
"import Capless.Tactics",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Subtyping",
"import Capless.Renaming.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Subcapt.trename",
"content": "theorem Subcapt.trename\n (h : Subcapt Γ C1 C2)\n (ρ : TVarMap Γ f Δ) :\n Subcapt Δ C1 C2"
}
] | [
{
"name": "Capless.SSubtyp.trename_motive1",
"content": "def SSubtyp.trename_motive1\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop :=\n ∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarMap Γ f Δ),\n ESubtyp Δ (E1.trename f) (E2.trename f)"
},
{
"name": "Capless... | [
{
"name": "Capless.Subbound.trename",
"content": "theorem Subbound.trename\n (h : Subbound Γ T1 T2)\n (ρ : TVarMap Γ f Δ) :\n Subbound Δ T1 T2"
}
] | import Capless.Tactics
import Capless.Subtyping
import Capless.Renaming.Basic
import Capless.Renaming.Type.Subcapturing
namespace Capless
def SSubtyp.trename_motive1
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarMap Γ f Δ),
ESubtyp Δ (E1.trename f) (E2.trename f)
def SSubtyp.trename_motive2
(Γ : Context n m k)
(T1 : CType n m k)
(T2 : CType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarMap Γ f Δ),
CSubtyp Δ (T1.trename f) (T2.trename f)
def SSubtyp.trename_motive3
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {m'} (f : FinFun m m') (Δ : Context n m' k) (ρ : TVarMap Γ f Δ),
SSubtyp Δ (S1.trename f) (S2.trename f) | theorem SSubtyp.trename
(h : SSubtyp Γ S1 S2)
(ρ : TVarMap Γ f Δ) :
SSubtyp Δ (S1.trename f) (S2.trename f) := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.trename_motive1 Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.trename_motive2 Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.trename_motive3 Γ S1 S2)
(t := h) (ρ := ρ)
case exist =>
unfold trename_motive1 trename_motive2
repeat intro
simp [EType.trename]
apply ESubtyp.exist
rename_i ih _ _ _ _
apply ih; apply TVarMap.cext; trivial
case type =>
unfold trename_motive1 trename_motive2
repeat intro
simp [EType.trename]
apply ESubtyp.type
aesop
case capt =>
unfold trename_motive2 trename_motive3
repeat intro
simp [CType.trename]
apply CSubtyp.capt
apply Subcapt.trename <;> trivial
aesop
case top =>
unfold trename_motive3
repeat intro
simp [SType.trename]
apply SSubtyp.top
case refl =>
unfold trename_motive3
repeat intro
apply refl
case trans =>
unfold trename_motive3
repeat intro
apply trans <;> aesop
case tvar =>
unfold trename_motive3
repeat intro
simp [SType.trename]
apply tvar
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.trename] at hb1
exact hb1
case tinstl =>
unfold trename_motive3
repeat intro
simp [SType.trename]
apply tinstl
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.trename] at hb1
exact hb1
case tinstr =>
unfold trename_motive3
repeat intro
simp [SType.trename]
apply tinstr
rename_i hb _ _ _ ρ
have hb1 := ρ.tmap _ _ hb
simp [TBinding.trename] at hb1
exact hb1
case boxed =>
unfold trename_motive2 trename_motive3
repeat intro
simp [SType.trename]
apply boxed
aesop
case label =>
unfold trename_motive3
repeat intro
simp [SType.trename]
apply label
aesop
case xforall =>
unfold trename_motive1 trename_motive3
repeat intro
simp [SType.trename]
apply xforall
aesop
rename_i ih2 _ _ _ _
apply ih2; apply TVarMap.ext; easy
case tforall =>
unfold trename_motive1 trename_motive3
repeat intro
simp [SType.trename]
apply tforall
aesop
rename_i ih2 _ _ _ _
apply ih2; apply TVarMap.text; easy
case cforall =>
unfold trename_motive1 trename_motive3
repeat intro
simp [SType.trename]
apply cforall
{ apply Subbound.trename <;> easy }
{ rename_i ih2 _ _ _ _
apply ih2; apply TVarMap.cext; easy } | 6 | 45 | false | Type systems |
74 | Capless.SSubtyp.sub_dealias_cforall_inv | theorem SSubtyp.sub_dealias_cforall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.cforall B1 E1))
(h2 : SType.Dealias Γ S2 (SType.cforall B2 E2))
(hs : SSubtyp Γ S1 S2) :
Subbound Γ B2 B1 ∧ ESubtyp (Γ.cvar (CBinding.bound B2)) E1 E2 | capless-lean | Capless/Inversion/Subtyping.lean | [
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Inversion.Basic",
"import Capless.Narrowing",
"import Capless.Subtyping",
"import Capless.Store",
"import Capless.Inversion.Context"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Exists",
"module": "Init.Core"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "refl",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"name": "Context.tbound_inj",
"content": "theorem Context.tbound_inj\n (h1 : Context.TBound Γ X b1)\n (h2 : Context.TBound Γ X b2) : b1 = b2"
},
{
"name": "Context.tvar_tbound_succ_inv",
"content": "theorem Context.tvar_tbound_succ_inv\n (hb : Context.TBound (Γ.tvar p) (Fin.succ X) b) :\n ... | [
{
"name": "Capless.SSubtyp.dealias_right_cforall.emotive",
"content": "def SSubtyp.dealias_right_cforall.emotive\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop := True"
},
{
"name": "Capless.SSubtyp.dealias_right_cforall.cmotive",
"content": "def SSubtyp.dealias_rig... | [
{
"name": "Capless.SSubtyp.dealias_right_cforall",
"content": "theorem SSubtyp.dealias_right_cforall\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.cforall B2 E2)) :\n ∃ B1 E1, SType.Dealias Γ S1 (SType.cforall B1 E1)"
},
{
"name": "Capless.SType.dealias_cforall_inj'",... | import Capless.Subtyping
import Capless.Store
import Capless.Inversion.Basic
import Capless.Inversion.Context
import Capless.Subtyping.Basic
import Capless.Narrowing
namespace Capless
def SSubtyp.dealias_right_cforall.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_right_cforall.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_right_cforall.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {B2 E2} (ht : Γ.IsTight) (hd : SType.Dealias Γ S2 (SType.cforall B2 E2)),
∃ B1 E1, SType.Dealias Γ S1 (SType.cforall B1 E1)
theorem SSubtyp.dealias_right_cforall
(h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)
(hd : SType.Dealias Γ S2 (SType.cforall B2 E2)) :
∃ B1 E1, SType.Dealias Γ S1 (SType.cforall B1 E1)
def SSubtyp.dealias_cforall_inv.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_cforall_inv.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_cforall_inv.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {B1 E1 B2 E2}
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.cforall B1 E1))
(h2 : SType.Dealias Γ S2 (SType.cforall B2 E2)),
Subbound Γ B2 B1 ∧ ESubtyp (Γ.cvar (CBinding.bound B2)) E1 E2 | theorem SSubtyp.sub_dealias_cforall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.cforall B1 E1))
(h2 : SType.Dealias Γ S2 (SType.cforall B2 E2))
(hs : SSubtyp Γ S1 S2) :
Subbound Γ B2 B1 ∧ ESubtyp (Γ.cvar (CBinding.bound B2)) E1 E2 := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.dealias_cforall_inv.emotive Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.dealias_cforall_inv.cmotive Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.dealias_cforall_inv.smotive Γ S1 S2)
(t := hs) (h1 := h1) (h2 := h2) (ht := ht)
case exist => aesop
case type => aesop
case capt => unfold dealias_cforall_inv.cmotive; aesop
case top =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd2
cases hd2
case refl =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd1 hd2
have h := SType.dealias_cforall_inj hd1 hd2
cases h; subst_vars
apply And.intro
{ apply Subbound.refl }
{ apply ESubtyp.refl }
case trans =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hs2 ih1 ih2 B1 E1 B2 E2 ht hd1 hd2
have h := SSubtyp.dealias_right_cforall hs2 ht hd2
have ⟨B3, E3, hd3⟩ := h
have ⟨he11, he12⟩ := ih1 ht hd1 hd3
have ⟨he21, he22⟩ := ih2 ht hd3 hd2
constructor
{ apply Subbound.trans <;> easy }
{ apply ESubtyp.trans
{ apply ESubtyp.cnarrow <;> easy }
{ easy } }
case tinstl =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_cforall_inj hd1 hd2
cases h
subst_vars
apply And.intro
{ apply Subbound.refl }
{ apply ESubtyp.refl }
case tinstr =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_cforall_inj hd1 hd2
cases h
subst_vars
apply And.intro
{ apply Subbound.refl }
{ apply ESubtyp.refl }
case tvar =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
case boxed =>
unfold dealias_cforall_inv.cmotive dealias_cforall_inv.smotive
repeat intro
rename_i hd
cases hd
case xforall =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd
cases hd
case tforall =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd
cases hd
case cforall =>
unfold dealias_cforall_inv.emotive dealias_cforall_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1; cases hd2
rename_i ih _ _
trivial
case label =>
unfold dealias_cforall_inv.smotive
repeat intro
rename_i hd
cases hd | 7 | 120 | false | Type systems |
75 | Capless.SSubtyp.sub_dealias_forall_inv | theorem SSubtyp.sub_dealias_forall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.forall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.forall T2 E2))
(hs : SSubtyp Γ S1 S2) :
CSubtyp Γ T2 T1 ∧ ESubtyp (Γ.var T2) E1 E2 | capless-lean | Capless/Inversion/Subtyping.lean | [
"import Capless.Narrowing.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Narrowing.TypedCont",
"import Capless.Inversion.Basic",
"import Capless.Narrowing",
"import Capless.Subtyping",
"import Capless.Store",
"import Capless.Inversion.Context"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "refl",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"name": "Context.tbound_inj",
"content": "theorem Context.tbound_inj\n (h1 : Context.TBound Γ X b1)\n (h2 : Context.TBound Γ X b2) : b1 = b2"
},
{
"name": "Context.tvar_tbound_succ_inv",
"content": "theorem Context.tvar_tbound_succ_inv\n (hb : Context.TBound (Γ.tvar p) (Fin.succ X) b) :\n ... | [
{
"name": "Capless.SSubtyp.dealias_right_forall.emotive",
"content": "def SSubtyp.dealias_right_forall.emotive\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop := True"
},
{
"name": "Capless.SSubtyp.dealias_right_forall.cmotive",
"content": "def SSubtyp.dealias_right_... | [
{
"name": "Capless.SSubtyp.dealias_right_forall",
"content": "theorem SSubtyp.dealias_right_forall\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.forall T2 E2)) :\n ∃ T1 E1, SType.Dealias Γ S1 (SType.forall T1 E1)"
},
{
"name": "Capless.SType.dealias_forall_inj'",
... | import Capless.Subtyping
import Capless.Store
import Capless.Inversion.Basic
import Capless.Inversion.Context
import Capless.Subtyping.Basic
import Capless.Narrowing
namespace Capless
def SSubtyp.dealias_right_forall.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_right_forall.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_right_forall.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T2 E2} (ht : Γ.IsTight) (hd : SType.Dealias Γ S2 (SType.forall T2 E2)),
∃ T1 E1, SType.Dealias Γ S1 (SType.forall T1 E1)
theorem SSubtyp.dealias_right_forall
(h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)
(hd : SType.Dealias Γ S2 (SType.forall T2 E2)) :
∃ T1 E1, SType.Dealias Γ S1 (SType.forall T1 E1)
def SSubtyp.dealias_forall_inv.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_forall_inv.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_forall_inv.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T1 E1 T2 E2}
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.forall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.forall T2 E2)),
CSubtyp Γ T2 T1 ∧ ESubtyp (Γ.var T2) E1 E2 | theorem SSubtyp.sub_dealias_forall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.forall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.forall T2 E2))
(hs : SSubtyp Γ S1 S2) :
CSubtyp Γ T2 T1 ∧ ESubtyp (Γ.var T2) E1 E2 := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.dealias_forall_inv.emotive Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.dealias_forall_inv.cmotive Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.dealias_forall_inv.smotive Γ S1 S2)
(t := hs) (h1 := h1) (h2 := h2) (ht := ht)
case exist => aesop
case type => aesop
case capt => unfold dealias_forall_inv.cmotive; aesop
case top =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd2
cases hd2
case refl =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd1 hd2
have h := SType.dealias_forall_inj hd1 hd2
cases h; subst_vars
constructor
{ apply CSubtyp.refl }
{ apply ESubtyp.refl }
case xforall =>
unfold dealias_forall_inv.emotive dealias_forall_inv.cmotive dealias_forall_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1; cases hd2
aesop
case trans =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hs2 ih1 ih2 T1 E1 T2 E2 ht hd1 hd2
have h := SSubtyp.dealias_right_forall hs2 ht hd2
have ⟨T3, E3, hd3⟩ := h
have ⟨hc1, he1⟩ := ih1 ht hd1 hd3
have ⟨hc2, he2⟩ := ih2 ht hd3 hd2
have he1' := he1.narrow hc2
constructor
{ apply CSubtyp.trans <;> trivial }
{ apply ESubtyp.trans <;> trivial }
case tinstl =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_forall_inj hd1 hd2
cases h
subst_vars
constructor
{ apply CSubtyp.refl }
{ apply ESubtyp.refl }
case tinstr =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_forall_inj hd1 hd2
cases h
subst_vars
constructor
{ apply CSubtyp.refl }
{ apply ESubtyp.refl }
case tvar =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
case boxed =>
unfold dealias_forall_inv.cmotive dealias_forall_inv.smotive
repeat intro
rename_i hd
cases hd
case label =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd
cases hd
case tforall =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd
cases hd
case cforall =>
unfold dealias_forall_inv.smotive
repeat intro
rename_i hd
cases hd | 5 | 128 | false | Type systems |
76 | Capless.SSubtyp.sub_dealias_tforall_inv | theorem SSubtyp.sub_dealias_tforall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.tforall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.tforall T2 E2))
(hs : SSubtyp Γ S1 S2) :
SSubtyp Γ T2 T1 ∧ ESubtyp (Γ.tvar (TBinding.bound T2)) E1 E2 | capless-lean | Capless/Inversion/Subtyping.lean | [
"import Capless.Narrowing.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Inversion.Basic",
"import Capless.Narrowing",
"import Capless.Subtyping",
"import Capless.Store",
"import Capless.Inversion.Context"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Exists",
"module": "Init.Core"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "refl",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"name": "Context.tbound_inj",
"content": "theorem Context.tbound_inj\n (h1 : Context.TBound Γ X b1)\n (h2 : Context.TBound Γ X b2) : b1 = b2"
},
{
"name": "Context.tvar_tbound_succ_inv",
"content": "theorem Context.tvar_tbound_succ_inv\n (hb : Context.TBound (Γ.tvar p) (Fin.succ X) b) :\n ... | [
{
"name": "Capless.SSubtyp.dealias_right_tforall.emotive",
"content": "def SSubtyp.dealias_right_tforall.emotive\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop := True"
},
{
"name": "Capless.SSubtyp.dealias_right_tforall.cmotive",
"content": "def SSubtyp.dealias_rig... | [
{
"name": "Capless.SSubtyp.dealias_right_tforall",
"content": "theorem SSubtyp.dealias_right_tforall\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.tforall T2 E2)) :\n ∃ T1 E1, SType.Dealias Γ S1 (SType.tforall T1 E1)"
},
{
"name": "Capless.SType.dealias_tforall_inj'",... | import Capless.Subtyping
import Capless.Store
import Capless.Inversion.Basic
import Capless.Inversion.Context
import Capless.Subtyping.Basic
import Capless.Narrowing
namespace Capless
def SSubtyp.dealias_right_tforall.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_right_tforall.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_right_tforall.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T2 E2} (ht : Γ.IsTight) (hd : SType.Dealias Γ S2 (SType.tforall T2 E2)),
∃ T1 E1, SType.Dealias Γ S1 (SType.tforall T1 E1)
theorem SSubtyp.dealias_right_tforall
(h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)
(hd : SType.Dealias Γ S2 (SType.tforall T2 E2)) :
∃ T1 E1, SType.Dealias Γ S1 (SType.tforall T1 E1)
def SSubtyp.dealias_tforall_inv.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_tforall_inv.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_tforall_inv.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T1 E1 T2 E2}
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.tforall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.tforall T2 E2)),
SSubtyp Γ T2 T1 ∧ ESubtyp (Γ.tvar (TBinding.bound T2)) E1 E2 | theorem SSubtyp.sub_dealias_tforall_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.tforall T1 E1))
(h2 : SType.Dealias Γ S2 (SType.tforall T2 E2))
(hs : SSubtyp Γ S1 S2) :
SSubtyp Γ T2 T1 ∧ ESubtyp (Γ.tvar (TBinding.bound T2)) E1 E2 := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 h => SSubtyp.dealias_tforall_inv.emotive Γ E1 E2)
(motive_2 := fun Γ C1 C2 h => SSubtyp.dealias_tforall_inv.cmotive Γ C1 C2)
(motive_3 := fun Γ S1 S2 h => SSubtyp.dealias_tforall_inv.smotive Γ S1 S2)
(t := hs) (h1 := h1) (h2 := h2) (ht := ht)
case exist => aesop
case type => aesop
case capt => unfold dealias_tforall_inv.cmotive; aesop
case top =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd2
cases hd2
case refl =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd1 hd2
have h := SType.dealias_tforall_inj hd1 hd2
cases h; subst_vars
constructor
{ apply SSubtyp.refl }
{ apply ESubtyp.refl }
case trans =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hs1 hs2 ih1 ih2 T1 E1 T2 E2 ht hd1 hd2
have h := SSubtyp.dealias_right_tforall hs2 ht hd2
have ⟨T3, E3, hd3⟩ := h
have ⟨hs1, he1⟩ := ih1 ht hd1 hd3
have ⟨hs2, he2⟩ := ih2 ht hd3 hd2
apply And.intro
{ apply! SSubtyp.trans }
{ apply? ESubtyp.trans
apply? he1.tnarrow }
case tvar =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
case tinstl =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_tforall_inj hd1 hd2
cases h
subst_vars
constructor
{ apply SSubtyp.refl }
{ apply ESubtyp.refl }
case tinstr =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_tforall_inj hd1 hd2
cases h
subst_vars
constructor
{ apply SSubtyp.refl }
{ apply ESubtyp.refl }
case boxed =>
unfold dealias_tforall_inv.cmotive dealias_tforall_inv.smotive
repeat intro
rename_i hd
cases hd
case label =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd
cases hd
case xforall =>
unfold dealias_tforall_inv.emotive dealias_tforall_inv.cmotive dealias_tforall_inv.smotive
repeat intro
rename_i hd
cases hd
case tforall =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1; cases hd2
aesop
case cforall =>
unfold dealias_tforall_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1 | 5 | 121 | false | Type systems |
77 | Capless.SSubtyp.sub_dealias_boxed_inv | theorem SSubtyp.sub_dealias_boxed_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.box T1))
(h2 : SType.Dealias Γ S2 (SType.box T2))
(hs : SSubtyp Γ S1 S2) :
CSubtyp Γ T1 T2 | capless-lean | Capless/Inversion/Subtyping.lean | [
"import Capless.Inversion.Basic",
"import Capless.Narrowing",
"import Capless.Subtyping.Basic",
"import Capless.Subtyping",
"import Capless.Store",
"import Capless.Inversion.Context"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "refl",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"name": "Context.tbound_inj",
"content": "theorem Context.tbound_inj\n (h1 : Context.TBound Γ X b1)\n (h2 : Context.TBound Γ X b2) : b1 = b2"
},
{
"name": "Context.tvar_tbound_succ_inv",
"content": "theorem Context.tvar_tbound_succ_inv\n (hb : Context.TBound (Γ.tvar p) (Fin.succ X) b) :\n ... | [
{
"name": "Capless.SSubtyp.dealias_right_boxed.emotive",
"content": "def SSubtyp.dealias_right_boxed.emotive\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop := True"
},
{
"name": "Capless.SSubtyp.dealias_right_boxed.cmotive",
"content": "def SSubtyp.dealias_right_box... | [
{
"name": "Capless.SSubtyp.dealias_right_boxed",
"content": "theorem SSubtyp.dealias_right_boxed\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.box T2)) :\n ∃ T1, SType.Dealias Γ S1 (SType.box T1)"
},
{
"name": "Capless.SType.dealias_boxed_inj'",
"content": "theore... | import Capless.Subtyping
import Capless.Store
import Capless.Inversion.Basic
import Capless.Inversion.Context
import Capless.Subtyping.Basic
import Capless.Narrowing
namespace Capless
def SSubtyp.dealias_right_boxed.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_right_boxed.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_right_boxed.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T2} (ht : Γ.IsTight) (hd : SType.Dealias Γ S2 (SType.box T2)),
∃ T1, SType.Dealias Γ S1 (SType.box T1)
theorem SSubtyp.dealias_right_boxed
(h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)
(hd : SType.Dealias Γ S2 (SType.box T2)) :
∃ T1, SType.Dealias Γ S1 (SType.box T1)
def SSubtyp.dealias_boxed_inv.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_boxed_inv.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_boxed_inv.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T1 T2}
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.box T1))
(h2 : SType.Dealias Γ S2 (SType.box T2)),
CSubtyp Γ T1 T2 | theorem SSubtyp.sub_dealias_boxed_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.box T1))
(h2 : SType.Dealias Γ S2 (SType.box T2))
(hs : SSubtyp Γ S1 S2) :
CSubtyp Γ T1 T2 := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 _ => SSubtyp.dealias_boxed_inv.emotive Γ E1 E2)
(motive_2 := fun Γ C1 C2 _ => SSubtyp.dealias_boxed_inv.cmotive Γ C1 C2)
(motive_3 := fun Γ S1 S2 _ => SSubtyp.dealias_boxed_inv.smotive Γ S1 S2)
(t := hs) (h1 := h1) (h2 := h2) (ht := ht)
case exist => aesop
case type => aesop
case capt => unfold dealias_boxed_inv.cmotive; aesop
case top =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd2
cases hd2
case refl =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd1 hd2
have h := SType.dealias_boxed_inj hd1 hd2
cases h
apply CSubtyp.refl
case trans =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hs2 ih1 ih2 T1 T2 ht hd1 hd2
have h := SSubtyp.dealias_right_boxed hs2 ht hd2
have ⟨T3, hd3⟩ := h
have hc1 := ih1 ht hd1 hd3
have hc2 := ih2 ht hd3 hd2
apply CSubtyp.trans <;> trivial
case tinstl =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_boxed_inj hd1 hd2
cases h
apply CSubtyp.refl
case tinstr =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_boxed_inj hd1 hd2
cases h
apply CSubtyp.refl
case tvar =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
case boxed =>
unfold dealias_boxed_inv.cmotive dealias_boxed_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1; cases hd2
rename_i ih _ _
trivial
case xforall =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd
cases hd
case tforall =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd
cases hd
case cforall =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd
cases hd
case label =>
unfold dealias_boxed_inv.smotive
repeat intro
rename_i hd
cases hd | 7 | 109 | false | Type systems |
78 | Capless.SSubtyp.sub_dealias_label_inv | theorem SSubtyp.sub_dealias_label_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.label T1))
(h2 : SType.Dealias Γ S2 (SType.label T2))
(hs : SSubtyp Γ S1 S2) :
SSubtyp Γ T2 T1 | capless-lean | Capless/Inversion/Subtyping.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Subtyping.Basic",
"import Capless.Inversion.Basic",
"import Capless.Narrowing",
"import Capless.Subtyping",
"import Capless.Store",
"import Capless.Inversion.Context"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Exists",
"module": "Init.Core"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "refl",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"name": "ESubtyp.refl",
"content": "theorem ESubtyp.refl :\n ESubtyp Γ E E"
},
{
"name": "CSubtyp.refl",
"content": "theorem CSubtyp.refl :\n CSubtyp Γ T T"
},
{
"name": "Context.tbound_inj",
"content": "theorem Context.tbound_inj\n (h1 : Context.TBound Γ X b1)\n (h2 : Context.... | [
{
"name": "Capless.SSubtyp.dealias_right_label.emotive",
"content": "def SSubtyp.dealias_right_label.emotive\n (Γ : Context n m k)\n (E1 : EType n m k)\n (E2 : EType n m k)\n : Prop := True"
},
{
"name": "Capless.SSubtyp.dealias_right_label.cmotive",
"content": "def SSubtyp.dealias_right_lab... | [
{
"name": "Capless.SSubtyp.dealias_right_label",
"content": "theorem SSubtyp.dealias_right_label\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.label T2)) :\n ∃ T1, SType.Dealias Γ S1 (SType.label T1)"
},
{
"name": "Capless.SType.dealias_label_inj'",
"content": "th... | import Capless.Subtyping
import Capless.Store
import Capless.Inversion.Basic
import Capless.Inversion.Context
import Capless.Subtyping.Basic
import Capless.Narrowing
namespace Capless
def SSubtyp.dealias_right_label.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_right_label.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_right_label.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T2} (ht : Γ.IsTight) (hd : SType.Dealias Γ S2 (SType.label T2)),
∃ T1, SType.Dealias Γ S1 (SType.label T1)
theorem SSubtyp.dealias_right_label
(h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)
(hd : SType.Dealias Γ S2 (SType.label T2)) :
∃ T1, SType.Dealias Γ S1 (SType.label T1)
def SSubtyp.dealias_label_inv.emotive
(Γ : Context n m k)
(E1 : EType n m k)
(E2 : EType n m k)
: Prop := True
def SSubtyp.dealias_label_inv.cmotive
(Γ : Context n m k)
(C1 : CType n m k)
(C2 : CType n m k)
: Prop := True
def SSubtyp.dealias_label_inv.smotive
(Γ : Context n m k)
(S1 : SType n m k)
(S2 : SType n m k)
: Prop :=
∀ {T1 T2}
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.label T1))
(h2 : SType.Dealias Γ S2 (SType.label T2)),
SSubtyp Γ T2 T1 | theorem SSubtyp.sub_dealias_label_inv
(ht : Γ.IsTight)
(h1 : SType.Dealias Γ S1 (SType.label T1))
(h2 : SType.Dealias Γ S2 (SType.label T2))
(hs : SSubtyp Γ S1 S2) :
SSubtyp Γ T2 T1 := | := by
apply SSubtyp.rec
(motive_1 := fun Γ E1 E2 _ => SSubtyp.dealias_label_inv.emotive Γ E1 E2)
(motive_2 := fun Γ C1 C2 _ => SSubtyp.dealias_label_inv.cmotive Γ C1 C2)
(motive_3 := fun Γ S1 S2 _ => SSubtyp.dealias_label_inv.smotive Γ S1 S2)
(t := hs) (h1 := h1) (h2 := h2) (ht := ht)
case exist => aesop
case type => aesop
case capt => unfold dealias_label_inv.cmotive; aesop
case top =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd2
cases hd2
case refl =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd1 hd2
have h := SType.dealias_label_inj hd1 hd2
cases h
apply SSubtyp.refl
case trans =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hs2 ih1 ih2 T1 T2 ht hd1 hd2
have h := SSubtyp.dealias_right_label hs2 ht hd2
have ⟨T3, hd3⟩ := h
have hs1 := ih1 ht hd1 hd3
have hs2 := ih2 ht hd3 hd2
apply SSubtyp.trans <;> trivial
case tinstl =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_label_inj hd1 hd2
cases h
apply SSubtyp.refl
case tinstr =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
rename_i hd1 hd2
have h := SType.dealias_label_inj hd1 hd2
cases h
apply SSubtyp.refl
case tvar =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd _
cases hd
rename_i hb1 _ _ _ _ _ hb2 _
have h := Context.tbound_inj hb1 hb2
cases h
case boxed =>
unfold dealias_label_inv.cmotive dealias_label_inv.smotive
repeat intro
rename_i hd
cases hd
case xforall =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd
cases hd
case tforall =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd
cases hd
case cforall =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd
cases hd
case label =>
unfold dealias_label_inv.smotive
repeat intro
rename_i hd1 hd2
cases hd1; cases hd2
rename_i ih _ _
trivial | 5 | 112 | false | Type systems |
79 | Capless.progress | theorem progress
(ht : TypedState state Γ E) :
Progress state | capless-lean | Capless/Soundness/Progress.lean | [
"import Capless.Inversion.Context",
"import Capless.Weakening.IsValue",
"import Mathlib.Data.Fin.Basic",
"import Capless.WellScoped.Basic",
"import Capless.Inversion.Subtyping",
"import Capless.Inversion.Lookup",
"import Capless.Inversion.Typing",
"import Capless.Store",
"import Capless.Reduction",
... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
},
{
"name": "Fin.elim0",
"module": "Init.... | [
{
"name": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t",
"content": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t"
},
{
"name": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u",
"content": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u"
},
{
"name": "notat... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Term.IsValue.weaken",
"content": "theorem Term.IsValue.weaken\n (hv : Term.IsValue t) :\n Term.IsValue t.weaken"
},
{
"name": "Term.IsValue.tweaken",
"content": "theorem Term.IsValue.tweaken\n (hv : Term.IsValue t) :\n Term.IsValue t.tweaken"
},
{
"name": "Term.IsValue.cwe... | [
{
"name": "Capless.Progress",
"content": "inductive Progress : State n m k -> Prop where\n| halt_var :\n Progress ⟨σ, Cont.none, Term.var x⟩\n| halt_value {t : Term n m k} :\n t.IsValue ->\n Progress ⟨σ, Cont.none, t⟩\n| step :\n Reduce state state' ->\n Progress state"
}
] | [
{
"name": "Capless.Store.lookup_exists",
"content": "theorem Store.lookup_exists {σ : Store n m k} {x : Fin n} :\n (∃ v, Store.Bound σ x v ∧ v.IsValue) ∨ (∃ S, Store.LBound σ x S)"
},
{
"name": "Capless.Store.val_lookup_exists",
"content": "theorem Store.val_lookup_exists {σ : Store n m k} {x :... | import Mathlib.Data.Fin.Basic
import Capless.Reduction
import Capless.Narrowing.TypedCont
import Capless.Inversion.Lookup
import Capless.Inversion.Typing
import Capless.Weakening.IsValue
import Capless.WellScoped.Basic
namespace Capless
inductive Progress : State n m k -> Prop where
| halt_var :
Progress ⟨σ, Cont.none, Term.var x⟩
| halt_value {t : Term n m k} :
t.IsValue ->
Progress ⟨σ, Cont.none, t⟩
| step :
Reduce state state' ->
Progress state | theorem progress
(ht : TypedState state Γ E) :
Progress state := | := by
cases ht
case mk hs ht hsc hc =>
induction ht
case var =>
cases hc <;> aesop
case label =>
cases hc <;> aesop
case pack =>
cases hc <;> aesop
case sub hsub ih _ _ _ =>
apply ih <;> try easy
apply WellScoped.subcapt; easy; easy
apply! TypedCont.narrow
case abs => cases hc <;> aesop
case tabs => cases hc <;> aesop
case cabs => cases hc <;> aesop
case app =>
rename_i x _ _ _ _ hx _ _ _ σ _ _
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.val_lookup_exists (σ := σ) (x := x) hs hx (by aesop)
have ⟨Cv, Cv0, htv⟩ := Store.lookup_inv_typing_alt hb0 hs hx
have ⟨U0, t0, he⟩ := Typed.forall_inv hg hv0 htv
aesop
case tapp x _ _ _ hx _ σ _ _ =>
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.val_lookup_exists (σ := σ) (x := x) hs hx (by aesop)
have ⟨Cv, Cv0, htv⟩ := Store.lookup_inv_typing_alt hb0 hs hx
have ⟨U0, t0, he⟩ := Typed.tforall_inv hg hv0 htv
aesop
case capp x _ _ _ hx _ σ _ _ =>
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.val_lookup_exists (σ := σ) (x := x) hs hx (by aesop)
have ⟨Cv, Ct0, htv⟩ := Store.lookup_inv_typing_alt hb0 hs hx
have ⟨t0, he⟩ := Typed.cforall_inv hg hv0 htv
aesop
case letin => aesop
case letex => aesop
case bindt => aesop
case bindc => aesop
case invoke hx hy _ _ σ cont Ct =>
cases hsc; rename_i hsc _
have hg := TypedStore.is_tight hs
have ⟨S0, hl⟩ := Store.label_lookup_exists hs hx
have hl := Store.bound_label hl hs
have ⟨_, hsl⟩ := WellScoped.label_inv hsc hl
aesop
case boundary => aesop | 8 | 164 | false | Type systems |
80 | Capless.TypedCont.lweaken | theorem TypedCont.lweaken
(h : TypedCont Γ E cont E' Ct) :
TypedCont (Γ.label S) E.weaken cont.weaken E'.weaken Ct.weaken | capless-lean | Capless/Weakening/TypedCont/Term.lean | [
"import Capless.Type.Basic",
"import Capless.Basic",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subtyping",
"import Capless.CaptureSet",
"import Capless.Weakening.Subcapturing",
"import Capless.Store"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "SSubtyp.weaken",
"content": "theorem SSubtyp.weaken\n (h : SSubtyp Γ S1 S2) :\n ∀ b, SSubtyp (Γ.var b) S1.weaken S2.weaken"
},
{
"name": "Su... | [] | [
{
"name": "Capless.EType.weaken1_weaken",
"content": "theorem EType.weaken1_weaken (E : EType n m k) :\n E.weaken.weaken1 = E.weaken.weaken"
},
{
"name": "Capless.CaptureSet.weaken1_weaken",
"content": "theorem CaptureSet.weaken1_weaken (C : CaptureSet n k) :\n C.weaken.weaken1 = C.weaken.weak... | import Capless.Store
import Capless.Weakening.Typing
import Capless.Weakening.Subtyping
import Capless.Weakening.Subcapturing
namespace Capless | theorem TypedCont.lweaken
(h : TypedCont Γ E cont E' Ct) :
TypedCont (Γ.label S) E.weaken cont.weaken E'.weaken Ct.weaken := | := by
induction h
case none =>
simp [Cont.weaken]
apply none
apply? ESubtyp.lweaken
case cons ih =>
simp [Cont.weaken]
have heq : ∀ {n m k} {T0 : CType n m k}, (EType.type T0).weaken = EType.type T0.weaken := by
intro T0
simp [EType.weaken, EType.rename, CType.weaken]
-- rw [heq]
apply cons
{ rename_i ht _ _
have ht1 := ht.lweaken_ext (P := S)
rw [EType.weaken1_weaken] at ht1
rw [CaptureSet.weaken1_weaken] at ht1
exact ht1 }
{ apply WellScoped.lweaken; assumption }
{ exact ih }
case conse ih =>
simp [Cont.weaken, EType.weaken_ex]
apply conse
{ rename_i ht _ _
have ht1 := ht.lweaken_cext_ext (P := S)
rw [EType.weaken1_weaken] at ht1
rw [EType.weaken_cweaken] at ht1
rw [CaptureSet.weaken1_weaken] at ht1
rw [CaptureSet.weaken_cweaken] at ht1
exact ht1 }
{ apply WellScoped.lweaken; aesop }
{ exact ih }
case scope hs ih =>
simp [Cont.weaken]
apply scope
{ constructor; aesop }
{ aesop }
{ have h1 := hs.lweaken (S:=S)
aesop } | 7 | 140 | false | Type systems |
81 | Capless.TypedCont.weaken | theorem TypedCont.weaken
(h : TypedCont Γ E t E' C0) :
TypedCont (Γ.var T) E.weaken t.weaken E'.weaken C0.weaken | capless-lean | Capless/Weakening/TypedCont/Term.lean | [
"import Capless.Type.Basic",
"import Capless.Basic",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subtyping",
"import Capless.CaptureSet",
"import Capless.Weakening.Subcapturing",
"import Capless.Store"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "SSubtyp.weaken",
"content": "theorem SSubtyp.weaken\n (h : SSubtyp Γ S1 S2) :\n ∀ b, SSubtyp (Γ.var b) S1.weaken S2.weaken"
},
{
"name": "Su... | [] | [
{
"name": "Capless.EType.weaken1_weaken",
"content": "theorem EType.weaken1_weaken (E : EType n m k) :\n E.weaken.weaken1 = E.weaken.weaken"
},
{
"name": "Capless.CaptureSet.weaken1_weaken",
"content": "theorem CaptureSet.weaken1_weaken (C : CaptureSet n k) :\n C.weaken.weaken1 = C.weaken.weak... | import Capless.Store
import Capless.Weakening.Typing
import Capless.Weakening.Subtyping
import Capless.Weakening.Subcapturing
namespace Capless | theorem TypedCont.weaken
(h : TypedCont Γ E t E' C0) :
TypedCont (Γ.var T) E.weaken t.weaken E'.weaken C0.weaken := | := by
induction h
case none =>
simp [Cont.weaken]
apply none
apply? ESubtyp.weaken
case cons ih =>
simp [Cont.weaken]
have heq : ∀ {n m k} {T0 : CType n m k}, (EType.type T0).weaken = EType.type T0.weaken := by
intro T0
simp [EType.weaken, EType.rename, CType.weaken]
-- rw [heq]
apply cons
{ rename_i ht _ _
have ht1 := ht.weaken_ext (P := T)
rw [EType.weaken1_weaken] at ht1
rw [CaptureSet.weaken1_weaken] at ht1
exact ht1 }
{ apply WellScoped.weaken; assumption }
{ exact ih }
case conse ih =>
simp [Cont.weaken, EType.weaken_ex]
apply conse
{ rename_i ht _ _
have ht1 := ht.weaken_cext_ext (P := T)
rw [EType.weaken1_weaken] at ht1
rw [EType.weaken_cweaken] at ht1
rw [CaptureSet.weaken1_weaken] at ht1
rw [CaptureSet.weaken_cweaken] at ht1
exact ht1 }
{ apply WellScoped.weaken; aesop }
{ exact ih }
case scope hs ih =>
simp [Cont.weaken]
apply scope
{ constructor; aesop }
{ aesop }
{ have h1 := hs.weaken (T:=T)
aesop } | 5 | 128 | false | Type systems |
82 | Capless.TypedCont.cweaken | theorem TypedCont.cweaken
(h : TypedCont Γ E t E' Ct) :
TypedCont (Γ.cvar b) E.cweaken t.cweaken E'.cweaken Ct.cweaken | capless-lean | Capless/Weakening/TypedCont/Capture.lean | [
"import Capless.Type.Basic",
"import Capless.Basic",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subtyping",
"import Capless.CaptureSet",
"import Capless.Weakening.Subcapturing",
"import Capless.Store"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "SSubtyp.weaken",
"content": "theorem SSubtyp.weaken\n (h : SSubtyp Γ S1 S2) :\n ∀ b, SSubtyp (Γ.var b) S1.weaken S2.weaken"
},
{
"name": "Su... | [] | [
{
"name": "Capless.EType.cweaken_ex",
"content": "theorem EType.cweaken_ex (T : CType n m (k+1)) :\n (EType.ex T).cweaken = EType.ex T.cweaken1"
},
{
"name": "Capless.EType.cweaken_weaken",
"content": "theorem EType.cweaken_weaken (E : EType n m k) :\n E.weaken.cweaken = E.cweaken.weaken"
},... | import Capless.Store
import Capless.Weakening.Typing
import Capless.Weakening.Subtyping
import Capless.Weakening.Subcapturing
namespace Capless | theorem TypedCont.cweaken
(h : TypedCont Γ E t E' Ct) :
TypedCont (Γ.cvar b) E.cweaken t.cweaken E'.cweaken Ct.cweaken := | := by
induction h
case none =>
simp [Cont.cweaken]
apply none
apply? ESubtyp.cweaken
case cons ht hs _ ih =>
simp [Cont.cweaken, EType.cweaken_type]
apply cons
{ have ht1 := ht.cweaken_ext (b := b)
rw [EType.cweaken_weaken] at ht1
rw [CaptureSet.weaken_crename]
exact ht1 }
{ apply hs.cweaken }
{ exact ih }
case conse ht hs _ ih =>
simp [Cont.cweaken, EType.cweaken_ex]
apply conse
{ have ht1 := ht.cweaken_cext_ext (b := b)
rw [EType.cweaken1_weaken] at ht1
rw [EType.cweaken1_cweaken] at ht1
rw [CaptureSet.cweaken1_weaken] at ht1
rw [CaptureSet.cweaken1_cweaken] at ht1
exact ht1 }
{ apply hs.cweaken }
{ exact ih }
case scope hb _ hs ih =>
simp [Cont.cweaken]
apply scope
have hb1 := Context.LBound.there_cvar (b := b) hb
exact hb1
simp at ih
apply ih
have h := hs.cweaken (b:=b)
aesop | 5 | 118 | false | Type systems |
83 | Capless.Subcapt.rename | theorem Subcapt.rename
(h : Subcapt Γ C1 C2)
(ρ : VarMap Γ f Δ) :
Subcapt Δ (C1.rename f) (C2.rename f) | capless-lean | Capless/Renaming/Term/Subcapturing.lean | [
"import Capless.Subcapturing",
"import Mathlib.Data.Finset.Image",
"import Capless.Renaming.Basic",
"import Capless.CaptureSet"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.rename_union",
"content": "theorem CaptureSet.rename_union {C1 C2 : CaptureSet n k} {f : FinFun n n'} :\n (C1 ∪ C2).rename f = C1.rename f ∪ C2.rename f"
},
{
"name": "CaptureSet.rename_singleton",
"content": "theorem CaptureSet.rename_singleton {x : Fin n} {f : FinFun n n... | [] | [
{
"name": "Capless.CaptureSet.Subset.rename",
"content": "theorem CaptureSet.Subset.rename {C1 C2 : CaptureSet n k}\n (h : C1 ⊆ C2) :\n C1.rename f ⊆ C2.rename f"
}
] | import Capless.Subcapturing
import Capless.Renaming.Basic
import Mathlib.Data.Finset.Image
namespace Capless | theorem Subcapt.rename
(h : Subcapt Γ C1 C2)
(ρ : VarMap Γ f Δ) :
Subcapt Δ (C1.rename f) (C2.rename f) := | := by
induction h
case trans ih1 ih2 => apply trans <;> aesop
case subset hsub =>
apply subset
apply CaptureSet.Subset.rename; trivial
case union ih1 ih2 =>
simp [CaptureSet.rename_union]
apply union <;> aesop
case var hb =>
simp [CaptureSet.rename_singleton]
apply var
have hb1 := ρ.map _ _ hb
simp [EType.rename, CType.rename] at hb1
assumption
case cinstl hb =>
simp [CaptureSet.rename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename] at hb1
apply cinstl
assumption
case cinstr hb =>
simp [CaptureSet.rename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename] at hb1
apply cinstr
assumption
case cbound hb =>
simp [CaptureSet.rename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename, CBound.rename] at hb1
apply cbound
easy | 3 | 36 | false | Type systems |
84 | Capless.Store.val_lookup_exists | theorem Store.val_lookup_exists {σ : Store n m k} {x : Fin n}
(hs : TypedStore σ Γ) (hx : Typed Γ (Term.var x) (EType.type T) Cx)
(hvt : T.IsValue) :
∃ v, Store.Bound σ x v ∧ v.IsValue | capless-lean | Capless/Soundness/Progress.lean | [
"import Capless.Inversion.Context",
"import Capless.Weakening.IsValue",
"import Mathlib.Data.Fin.Basic",
"import Capless.WellScoped.Basic",
"import Capless.Inversion.Subtyping",
"import Capless.Inversion.Lookup",
"import Capless.Inversion.Typing",
"import Capless.Store",
"import Capless.Reduction",
... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
},
{
"name": "Fin.elim0",
"module": "Init.... | [
{
"name": "notation:50 \"∀(x:\" T \")\" U => SType.forall T U",
"content": "notation:50 \"∀(x:\" T \")\" U => SType.forall T U"
},
{
"name": "notation:50 \"∀[c<:\" B \"]\" T => SType.cforall B T",
"content": "notation:50 \"∀[c<:\" B \"]\" T => SType.cforall B T"
},
{
"name": "notation:50... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Term.IsValue.weaken",
"content": "theorem Term.IsValue.weaken\n (hv : Term.IsValue t) :\n Term.IsValue t.weaken"
},
{
"name": "Term.IsValue.tweaken",
"content": "theorem Term.IsValue.tweaken\n (hv : Term.IsValue t) :\n Term.IsValue t.tweaken"
},
{
"name": "Term.IsValue.cwe... | [] | [
{
"name": "Capless.Store.lookup_exists",
"content": "theorem Store.lookup_exists {σ : Store n m k} {x : Fin n} :\n (∃ v, Store.Bound σ x v ∧ v.IsValue) ∨ (∃ S, Store.LBound σ x S)"
}
] | import Mathlib.Data.Fin.Basic
import Capless.Reduction
import Capless.Narrowing.TypedCont
import Capless.Inversion.Lookup
import Capless.Inversion.Typing
import Capless.Weakening.IsValue
import Capless.WellScoped.Basic
namespace Capless | theorem Store.val_lookup_exists {σ : Store n m k} {x : Fin n}
(hs : TypedStore σ Γ) (hx : Typed Γ (Term.var x) (EType.type T) Cx)
(hvt : T.IsValue) :
∃ v, Store.Bound σ x v ∧ v.IsValue := | := by
have hg := TypedStore.is_tight hs
have h := Store.lookup_exists (σ := σ) (x := x)
cases h
case inl h => easy
case inr h =>
have ⟨S, hl⟩ := h
have hb := Store.bound_label hl hs
have ⟨S0, hb0, hsub⟩ := Typed.label_inv hx hb
have h := Context.lbound_inj hb hb0
subst_vars
cases hvt
case capt hvt =>
cases hsub; rename_i hsub
cases hvt
case xforall =>
have ⟨_, _, hd1⟩ := SSubtyp.dealias_right_forall hsub hg (by constructor)
cases hd1
case tforall =>
have ⟨_, _, hd1⟩ := SSubtyp.dealias_right_tforall hsub hg (by constructor)
cases hd1
case cforall =>
have ⟨_, _, hd1⟩ := SSubtyp.dealias_right_cforall hsub hg (by constructor)
cases hd1
case box =>
have ⟨_, hd1⟩ := SSubtyp.dealias_right_boxed hsub hg (by constructor)
cases hd1 | 4 | 102 | false | Type systems |
85 | Capless.Typed.canonical_form_tlam' | theorem Typed.canonical_form_tlam'
(ht : Γ.IsTight)
(hd : SType.Dealias Γ S0 (SType.tforall S' E))
(he1 : t0 = Term.tlam S t)
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
SSubtyp Γ S' S ∧
Typed (Γ.tvar (TBinding.bound S')) t E Cf | capless-lean | Capless/Inversion/Typing.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Narrowing.Typing",
"import Capless.Tactics",
"import Capless.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Weakening.Subtyping",
"import Capless.Inversion.Subtyping",
"import Capless.Narrowing",
... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t",
"content": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t"
},
{
"name": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u",
"content": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u"
},
{
"name": "notat... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Typed.tnarrow",
"content": "theorem Typed.tnarrow\n (h : Typed (Γ,X<: S) t E Ct)\n (hs : SSubtyp Γ S' S) :\n Typed (Γ,X<: S') t E Ct"
},
{
"name": "SSubtyp.sub_dealias_tforall_inv",
"content": "theorem SSubtyp.sub_dealias_tforall_inv\n (ht : Γ.IsTight)\n (h1 : SType.Dealias Γ S1 ... | [] | [] | import Capless.Tactics
import Capless.Typing
import Capless.Subtyping.Basic
import Capless.Subcapturing.Basic
import Capless.Narrowing
import Capless.Weakening.Subcapturing
import Capless.Inversion.Context
import Capless.Inversion.Subtyping
namespace Capless | theorem Typed.canonical_form_tlam'
(ht : Γ.IsTight)
(hd : SType.Dealias Γ S0 (SType.tforall S' E))
(he1 : t0 = Term.tlam S t)
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
SSubtyp Γ S' S ∧
Typed (Γ.tvar (TBinding.bound S')) t E Cf := | := by
induction h <;> try (solve | cases he1 | cases he2)
case tabs =>
cases he1; cases he2
cases hd
constructor
apply SSubtyp.refl
trivial
case sub hs ih =>
subst he2
cases hs
rename_i hs
cases hs
rename_i hsc hs
have ⟨S1, E1, hd3⟩ := SSubtyp.dealias_right_tforall hs ht hd
have ih := ih ht hd3 he1 rfl
have h := SSubtyp.sub_dealias_tforall_inv ht hd3 hd hs
have ⟨hs1, ht1⟩ := ih
have ⟨hs2, ht2⟩ := h
apply And.intro
{ apply! SSubtyp.trans }
{ constructor
apply? Typed.sub
apply ht1.tnarrow; assumption; apply Subcapt.refl
apply hsc.tweaken
apply ESubtyp.refl } | 5 | 68 | false | Type systems |
86 | Capless.Subcapt.crename | theorem Subcapt.crename
(h : Subcapt Γ C1 C2)
(ρ : CVarMap Γ f Δ) :
Subcapt Δ (C1.crename f) (C2.crename f) | capless-lean | Capless/Renaming/Capture/Subcapturing.lean | [
"import Capless.Subcapturing",
"import Mathlib.Data.Finset.Image",
"import Capless.Renaming.Basic",
"import Capless.CaptureSet"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.crename_csingleton",
"content": "theorem CaptureSet.crename_csingleton {x : Fin k} {f : FinFun k k'} :\n ({c=x} : CaptureSet n k).crename f = {c=f x}"
},
{
"name": "CaptureSet.crename_union",
"content": "theorem CaptureSet.crename_union {C1 C2 : CaptureSet n k} {f : FinFun... | [] | [
{
"name": "Capless.CaptureSet.Subset.crename",
"content": "theorem CaptureSet.Subset.crename {C1 C2 : CaptureSet n k}\n (h : C1 ⊆ C2) :\n C1.crename f ⊆ C2.crename f"
}
] | import Capless.Subcapturing
import Capless.Renaming.Basic
import Mathlib.Data.Finset.Image
namespace Capless | theorem Subcapt.crename
(h : Subcapt Γ C1 C2)
(ρ : CVarMap Γ f Δ) :
Subcapt Δ (C1.crename f) (C2.crename f) := | := by
induction h
case trans ih1 ih2 => apply trans <;> aesop
case subset hsub =>
apply subset
apply CaptureSet.Subset.crename; trivial
case union ih1 ih2 =>
simp [CaptureSet.crename_union]
apply union <;> aesop
case var hb =>
simp [CaptureSet.crename_singleton]
apply var
have hb1 := ρ.map _ _ hb
simp [EType.crename, CType.crename] at hb1
assumption
case cinstl hb =>
simp [CaptureSet.crename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename] at hb1
apply cinstl
assumption
case cinstr hb =>
simp [CaptureSet.crename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename] at hb1
apply cinstr
assumption
case cbound hb =>
simp [CaptureSet.crename_csingleton]
have hb1 := ρ.cmap _ _ hb
simp [CBinding.rename] at hb1
apply cbound
assumption | 3 | 43 | false | Type systems |
87 | Capless.Typed.boundary_body_typing | theorem Typed.boundary_body_typing {Γ : Context n m k} {S : SType n m k}
(ht : Typed ((Γ,c<:*),x:(Label[S.cweaken])^{c=0}) t E Ct) :
Typed ((Γ.label S),c:={x=0}) t E Ct | capless-lean | Capless/Typing/Boundary.lean | [
"import Capless.Renaming.Capture.Typing",
"import Capless.Renaming.Term.Subtyping",
"import Capless.Renaming.Term.Typing",
"import Capless.Renaming.Type.Subcapturing",
"import Capless.Basic",
"import Capless.Subst.Term.Subcapturing",
"import Capless.Renaming.Term.Subcapturing",
"import Capless.Capture... | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "abs",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Abs"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.cweaken",
"content": "theorem CSubtyp.cweaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.cvar b) E1.cweaken E2.cweaken"
},
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "ES... | [
{
"name": "Capless.VarRename.boundary",
"content": "def VarRename.boundary {Γ : Context n m k} {S : SType n m k} :\n VarMap\n ((Γ,c<:*),x:(Label[S.cweaken])^{c=0})\n FinFun.weaken.ext\n (((Γ.label S),c<:*),x:(Label[S.weaken.cweaken])^{c=0}) :="
},
{
"name": "Capless.CVarRename.boundary",
... | [
{
"name": "Capless.Term.copen_cweaken_ext",
"content": "theorem Term.copen_cweaken_ext {t : Term n m (k+1)} :\n (t.crename (FinFun.weaken.ext)).crename (FinFun.open 0) = t"
},
{
"name": "Capless.EType.copen_cweaken_ext",
"content": "theorem EType.copen_cweaken_ext {E : EType n m (k+1)} :\n (E.... | import Capless.Typing
import Capless.Weakening.Typing
import Capless.Narrowing.Typing
namespace Capless
def VarRename.boundary {Γ : Context n m k} {S : SType n m k} :
VarMap
((Γ,c<:*),x:(Label[S.cweaken])^{c=0})
FinFun.weaken.ext
(((Γ.label S),c<:*),x:(Label[S.weaken.cweaken])^{c=0}) :=
def CVarRename.boundary {Γ : Context n m k} {S : SType n m k} :
CVarMap
(((Γ.label S),c<:*),x:(Label[S.weaken.cweaken])^{c=0})
FinFun.weaken.ext
((((Γ.label S),c:={x=0}),c<:*),x:(Label[S.weaken.cweaken.cweaken])^{c=0}) :=
def CVarSubst.boundary {Γ : Context n m k} {S : SType n m k} :
CVarSubst
((((Γ.label S),c:={x=0}),c<:*),x:(Label[S.weaken.cweaken.cweaken])^{c=0})
(FinFun.open 0)
(((Γ.label S),c:={x=0}),x:(Label[S.weaken.cweaken])^{c=0}) :=
def VarSubst.boundary {Γ : Context n m k} {S : SType n m k} :
VarSubst
(((Γ.label S),c:={x=0}),x:(Label[S.weaken.cweaken])^{c=0})
(FinFun.open 0)
((Γ.label S),c:={x=0}) := | theorem Typed.boundary_body_typing {Γ : Context n m k} {S : SType n m k}
(ht : Typed ((Γ,c<:*),x:(Label[S.cweaken])^{c=0}) t E Ct) :
Typed ((Γ.label S),c:={x=0}) t E Ct := | := by
have h := ht.rename VarRename.boundary
have h := h.crename CVarRename.boundary
have h := h.csubst CVarSubst.boundary
simp [Term.copen_cweaken_ext, EType.copen_cweaken_ext, CaptureSet.copen_cweaken_ext] at h
have h := h.subst VarSubst.boundary
simp [Term.open_weaken_ext, EType.open_weaken_ext, CaptureSet.open_weaken_ext] at h
easy | 5 | 220 | false | Type systems |
88 | Capless.Typed.canonical_form_lam' | theorem Typed.canonical_form_lam'
(ht : Γ.IsTight)
(he1 : t0 = Term.lam T t) (hd2 : SType.Dealias Γ S0 (SType.forall T' E))
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
CSubtyp Γ T' T ∧
Typed (Γ.var T') t E (Cf.weaken ∪ {x=0}) | capless-lean | Capless/Inversion/Typing.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Narrowing.Typing",
"import Capless.Tactics",
"import Capless.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subtyping",
"import Capless.Narrowing.TypedC... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Typed.narrow",
"content": "theorem Typed.narrow\n (h : Typed (Γ,x: T) t E Ct)\n (hs : CSubtyp Γ T' T) :\n Typed (Γ,x: T') t E Ct"
},
{
"name": "CSubtyp.trans",
"content": "theorem CSubtyp.trans\n (h1 : CSubtyp Γ T1 T2)\n (h2 : CSubtyp Γ T2 T3) :\n CSubtyp Γ T1 T3"
},
{
"... | [] | [] | import Capless.Tactics
import Capless.Typing
import Capless.Subtyping.Basic
import Capless.Subcapturing.Basic
import Capless.Narrowing
import Capless.Weakening.Subcapturing
import Capless.Inversion.Context
import Capless.Inversion.Subtyping
namespace Capless | theorem Typed.canonical_form_lam'
(ht : Γ.IsTight)
(he1 : t0 = Term.lam T t) (hd2 : SType.Dealias Γ S0 (SType.forall T' E))
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
CSubtyp Γ T' T ∧
Typed (Γ.var T') t E (Cf.weaken ∪ {x=0}) := | := by
induction h <;> try (solve | cases he1 | cases he2)
case abs =>
cases he1; cases he2
cases hd2
constructor
{ apply CSubtyp.refl }
{ aesop }
case sub hs ih =>
subst he2
cases hs
rename_i hs
cases hs
rename_i hsc hs
have ⟨T1, E1, hd3⟩ := SSubtyp.dealias_right_forall hs ht hd2
have ih := ih ht he1 hd3 rfl
have h := SSubtyp.sub_dealias_forall_inv ht hd3 hd2 hs
have ⟨hs1, ht1⟩ := ih
have ⟨hs2, ht2⟩ := h
apply And.intro
{ apply! CSubtyp.trans }
{ apply Typed.sub <;> try easy
apply ht1.narrow
assumption
apply Subcapt.join
{ apply hsc.weaken }
{ apply Subcapt.refl } } | 4 | 106 | false | Type systems |
89 | Capless.Typed.canonical_form_clam' | theorem Typed.canonical_form_clam'
(ht : Γ.IsTight)
(hd : SType.Dealias Γ S0 (SType.cforall B' E))
(he1 : t0 = Term.clam B t)
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
Subbound Γ B' B ∧ Typed (Γ.cvar (CBinding.bound B')) t E Cf.cweaken | capless-lean | Capless/Inversion/Typing.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Narrowing.Typing",
"import Capless.Tactics",
"import Capless.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Narrowing.Subtyping",
"import Capless.Inversion.Subtyping",
"import Capless.Narrowing",
"import Capless.Weakening.Subcapturing"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2",
"content": "notation:50 Γ \" ⊢ \" E1 \" <:e \" E2 => ESubtyp Γ E1 E2"
},
{
"name": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2",
"content": "notation:50 Γ \" ⊢ \" T1 \" <:s \" T2 => SSubtyp Γ T1 T2"
},
{
... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "SSubtyp.dealias_right_cforall",
"content": "theorem SSubtyp.dealias_right_cforall\n (h : SSubtyp Γ S1 S2) (ht : Γ.IsTight)\n (hd : SType.Dealias Γ S2 (SType.cforall B2 E2)) :\n ∃ B1 E1, SType.Dealias Γ S1 (SType.cforall B1 E1)"
},
{
"name": "Typed.cnarrow",
"content": "theorem Type... | [] | [] | import Capless.Tactics
import Capless.Typing
import Capless.Subtyping.Basic
import Capless.Subcapturing.Basic
import Capless.Narrowing
import Capless.Weakening.Subcapturing
import Capless.Inversion.Context
import Capless.Inversion.Subtyping
namespace Capless | theorem Typed.canonical_form_clam'
(ht : Γ.IsTight)
(hd : SType.Dealias Γ S0 (SType.cforall B' E))
(he1 : t0 = Term.clam B t)
(he2 : E0 = EType.type (CType.capt Cf S0))
(h : Typed Γ t0 E0 Ct0) :
Subbound Γ B' B ∧ Typed (Γ.cvar (CBinding.bound B')) t E Cf.cweaken := | := by
induction h <;> try (solve | cases he1 | cases he2)
case cabs =>
cases he1; cases he2
cases hd
apply And.intro
{ apply Subbound.refl }
{ trivial }
case sub hs ih =>
subst he2
cases hs
rename_i hs
cases hs
rename_i hsc hs
have ⟨B1, E1, hd3⟩ := SSubtyp.dealias_right_cforall hs ht hd
have ⟨ih1, ih2⟩ := ih ht hd3 he1 rfl
have ⟨h1, h2⟩ := SSubtyp.sub_dealias_cforall_inv ht hd3 hd hs
constructor
{ apply Subbound.trans <;> easy }
apply Typed.sub
{ apply ih2.cnarrow; easy }
{ apply Subcapt.cweaken; easy }
{ easy } | 4 | 56 | false | Type systems |
90 | Capless.TypedCont.tweaken | theorem TypedCont.tweaken
(h : TypedCont Γ E t E' C0) :
TypedCont (Γ.tvar S) E.tweaken t.tweaken E'.tweaken C0 | capless-lean | Capless/Weakening/TypedCont/Type.lean | [
"import Capless.Type.Basic",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subcapturing",
"import Capless.Store",
"import Capless.Weakening.Subtyping"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t",
"content": "notation:50 \"λ[X<:\" S \"]\" t => Term.tlam S t"
},
{
"name": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u",
"content": "notation:40 \"let\" \"x=\" t \" in \" u => Term.letin t u"
},
{
"name": "notat... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "Subbound.tweaken",
"content": "theorem Subbound.tweaken\n (h : Subbound Γ B1 B2) :\n Subbound (Γ.tvar b) B1 B2"
},
{
"name": "Subbound.weake... | [] | [
{
"name": "Capless.EType.tweaken_ex",
"content": "theorem EType.tweaken_ex (T : CType n m (k+1)) :\n (EType.ex T).tweaken = EType.ex T.tweaken"
},
{
"name": "Capless.EType.tweaken_weaken",
"content": "theorem EType.tweaken_weaken (E : EType n m k) :\n E.weaken.tweaken = E.tweaken.weaken"
},
... | import Capless.Store
import Capless.Weakening.Typing
import Capless.Weakening.Subtyping
import Capless.Weakening.Subcapturing
namespace Capless | theorem TypedCont.tweaken
(h : TypedCont Γ E t E' C0) :
TypedCont (Γ.tvar S) E.tweaken t.tweaken E'.tweaken C0 := | := by
induction h
case none =>
simp [Cont.tweaken]
apply none
apply? ESubtyp.tweaken
case cons ht hs _ ih =>
simp [Cont.tweaken]
-- simp [EType.tweaken_type]
apply cons
{ have ht1 := ht.tweaken_ext (b := S)
rw [EType.tweaken_weaken] at ht1
exact ht1 }
{ apply hs.tweaken }
{ exact ih }
case conse ht hs _ ih =>
simp [Cont.tweaken]
simp [EType.tweaken_ex]
apply conse
{ have ht1 := ht.tweaken_cext_ext (b := S)
rw [EType.tweaken_weaken] at ht1
rw [EType.tweaken_cweaken] at ht1
exact ht1 }
{ apply hs.tweaken }
{ exact ih }
case scope hb _ hs ih =>
simp [Cont.tweaken]
apply scope
have hb1 := Context.LBound.there_tvar (b := S) hb
exact hb1
simp at ih
apply ih
have h := hs.tweaken (b:=S)
aesop | 5 | 125 | false | Type systems |
91 | Capless.SType.crename_rename_comm | theorem SType.crename_rename_comm (S : SType n m k) (f : FinFun n n') (g : FinFun k k') :
(S.rename f).crename g = (S.crename g).rename f :=
match S with
| SType.top => by simp [SType.rename, SType.crename]
| SType.tvar X => by simp [SType.rename, SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_rename_comm E1 f g
have ih2 := EType.crename_rename_comm E2 f.ext g
simp [SType.rename, SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_rename_comm S f g
have ih2 := EType.crename_rename_comm E f g
simp [SType.rename, SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_rename_comm E f g.ext
simp [SType.rename, CBound.crename_rename_comm, SType.crename, ih]
| SType.box T => by
have ih := CType.crename_rename_comm T f g
simp [SType.rename, SType.crename, ih]
| SType.label S => by
have ih := SType.crename_rename_comm S f g
simp [SType.rename, SType.crename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Type.Renaming",
"import Capless.Type.Core",
"import Capless.CaptureSet"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.crename_rename_comm",
"content": "theorem CaptureSet.crename_rename_comm {C : CaptureSet n k} {f : FinFun n n'} {g : FinFun k k'} :\n (C.rename f).crename g = (C.crename g).rename f"
}
] | [] | [
{
"name": "Capless.CBound.crename_rename_comm",
"content": "theorem CBound.crename_rename_comm {b : CBound n k} :\n (b.crename f).rename g = (b.rename g).crename f"
},
{
"name": "Capless.EType.crename_rename_comm",
"content": "theorem EType.crename_rename_comm (E : EType n m k) (f : FinFun n n'... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless | theorem SType.crename_rename_comm (S : SType n m k) (f : FinFun n n') (g : FinFun k k') :
(S.rename f).crename g = (S.crename g).rename f := | :=
match S with
| SType.top => by simp [SType.rename, SType.crename]
| SType.tvar X => by simp [SType.rename, SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_rename_comm E1 f g
have ih2 := EType.crename_rename_comm E2 f.ext g
simp [SType.rename, SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_rename_comm S f g
have ih2 := EType.crename_rename_comm E f g
simp [SType.rename, SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_rename_comm E f g.ext
simp [SType.rename, CBound.crename_rename_comm, SType.crename, ih]
| SType.box T => by
have ih := CType.crename_rename_comm T f g
simp [SType.rename, SType.crename, ih]
| SType.label S => by
have ih := SType.crename_rename_comm S f g
simp [SType.rename, SType.crename, ih] | 5 | 24 | false | Type systems |
92 | Capless.SType.rename_rename | theorem SType.rename_rename (S : SType n m k) (f : FinFun n n') (g : FinFun n' n'') :
(S.rename f).rename g = S.rename (g ∘ f) :=
match S with
| SType.top => by simp [SType.rename]
| SType.tvar X => by simp [SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.rename_rename E1 f g
have ih2 := EType.rename_rename E2 f.ext g.ext
simp [SType.rename, ih1, ih2, FinFun.ext_comp_ext]
| SType.tforall S E => by
have ih1 := SType.rename_rename S f g
have ih2 := EType.rename_rename E f g
simp [SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.rename_rename E f g
simp [SType.rename, CBound.rename_rename, ih]
| SType.box T => by
have ih := CType.rename_rename T f g
simp [SType.rename, ih]
| SType.label S => by
have ih := SType.rename_rename S f g
simp [SType.rename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Basic",
"import Capless.Type.Renaming",
"import Capless.Type.Core",
"import Capless.CaptureSet"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.rename_rename",
"content": "theorem CaptureSet.rename_rename {C : CaptureSet n k} :\n (C.rename f).rename g = C.rename (g ∘ f)"
},
{
"name": "FinFun.ext_comp_ext",
"content": "theorem FinFun.ext_comp_ext {f : FinFun n n'} {g : FinFun n' n''} :\n g.ext ∘ f.ext = FinFun.ext... | [] | [
{
"name": "Capless.CBound.rename_rename",
"content": "theorem CBound.rename_rename {b : CBound n k} :\n (b.rename f).rename g = b.rename (g ∘ f)"
},
{
"name": "Capless.EType.rename_rename",
"content": "theorem EType.rename_rename (E : EType n m k) (f : FinFun n n') (g : FinFun n' n'') :\n (E.r... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end | theorem SType.rename_rename (S : SType n m k) (f : FinFun n n') (g : FinFun n' n'') :
(S.rename f).rename g = S.rename (g ∘ f) := | :=
match S with
| SType.top => by simp [SType.rename]
| SType.tvar X => by simp [SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.rename_rename E1 f g
have ih2 := EType.rename_rename E2 f.ext g.ext
simp [SType.rename, ih1, ih2, FinFun.ext_comp_ext]
| SType.tforall S E => by
have ih1 := SType.rename_rename S f g
have ih2 := EType.rename_rename E f g
simp [SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.rename_rename E f g
simp [SType.rename, CBound.rename_rename, ih]
| SType.box T => by
have ih := CType.rename_rename T f g
simp [SType.rename, ih]
| SType.label S => by
have ih := SType.rename_rename S f g
simp [SType.rename, ih] | 4 | 20 | false | Type systems |
93 | Capless.SType.trename_rename_comm | theorem SType.trename_rename_comm (S : SType n m k) (f : FinFun n n') (g : FinFun m m') :
(S.trename g).rename f = (S.rename f).trename g :=
match S with
| SType.top => by simp [SType.trename, SType.rename]
| SType.tvar X => by simp [SType.trename, SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.trename_rename_comm E1 f g
have ih2 := EType.trename_rename_comm E2 f.ext g
simp [SType.trename, SType.rename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.trename_rename_comm S f g
have ih2 := EType.trename_rename_comm E f g.ext
simp [SType.trename, SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.trename_rename_comm E f g
simp [SType.trename, SType.rename, ih]
| SType.box T => by
have ih := CType.trename_rename_comm T f g
simp [SType.trename, SType.rename, ih]
| SType.label S => by
have ih := SType.trename_rename_comm S f g
simp [SType.trename, SType.rename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Type.Renaming",
"import Capless.Type.Core"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [] | [
{
"name": "Capless.EType.trename_rename_comm",
"content": "theorem EType.trename_rename_comm (E : EType n m k) (f : FinFun n n') (g : FinFun m m') :\n (E.trename g).rename f = (E.rename f).trename g"
},
{
"name": "Capless.CType.trename_rename_comm",
"content": "theorem CType.trename_rename_comm... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end | theorem SType.trename_rename_comm (S : SType n m k) (f : FinFun n n') (g : FinFun m m') :
(S.trename g).rename f = (S.rename f).trename g := | :=
match S with
| SType.top => by simp [SType.trename, SType.rename]
| SType.tvar X => by simp [SType.trename, SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.trename_rename_comm E1 f g
have ih2 := EType.trename_rename_comm E2 f.ext g
simp [SType.trename, SType.rename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.trename_rename_comm S f g
have ih2 := EType.trename_rename_comm E f g.ext
simp [SType.trename, SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.trename_rename_comm E f g
simp [SType.trename, SType.rename, ih]
| SType.box T => by
have ih := CType.trename_rename_comm T f g
simp [SType.trename, SType.rename, ih]
| SType.label S => by
have ih := SType.trename_rename_comm S f g
simp [SType.trename, SType.rename, ih] | 4 | 20 | false | Type systems |
94 | Capless.SType.rename_id | theorem SType.rename_id {S : SType n m k} :
S.rename FinFun.id = S :=
match S with
| SType.top => by simp [SType.rename]
| SType.tvar X => by simp [SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.rename_id (T := E1)
have ih2 := EType.rename_id (E := E2)
simp [SType.rename, FinFun.id_ext, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.rename_id (S := S)
have ih2 := EType.rename_id (E := E)
simp [SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.rename_id (E := E)
simp [SType.rename, CBound.rename_id, ih]
| SType.box T => by
have ih := CType.rename_id (T := T)
simp [SType.rename, ih]
| SType.label S => by
have ih := SType.rename_id (S := S)
simp [SType.rename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Basic",
"import Capless.Type.Renaming",
"import Capless.Type.Core",
"import Capless.CaptureSet"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.rename_id",
"content": "theorem CaptureSet.rename_id {C : CaptureSet n k} :\n C.rename FinFun.id = C"
},
{
"name": "FinFun.id_ext",
"content": "theorem FinFun.id_ext :\n (FinFun.ext (n := n) id) = id"
}
] | [] | [
{
"name": "Capless.CBound.rename_id",
"content": "theorem CBound.rename_id {b : CBound n k} :\n b.rename FinFun.id = b"
},
{
"name": "Capless.EType.rename_id",
"content": "theorem EType.rename_id {E : EType n m k} :\n E.rename FinFun.id = E"
},
{
"name": "Capless.CType.rename_id",
... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end
end
end
end
end | theorem SType.rename_id {S : SType n m k} :
S.rename FinFun.id = S := | :=
match S with
| SType.top => by simp [SType.rename]
| SType.tvar X => by simp [SType.rename]
| SType.forall E1 E2 => by
have ih1 := CType.rename_id (T := E1)
have ih2 := EType.rename_id (E := E2)
simp [SType.rename, FinFun.id_ext, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.rename_id (S := S)
have ih2 := EType.rename_id (E := E)
simp [SType.rename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.rename_id (E := E)
simp [SType.rename, CBound.rename_id, ih]
| SType.box T => by
have ih := CType.rename_id (T := T)
simp [SType.rename, ih]
| SType.label S => by
have ih := SType.rename_id (S := S)
simp [SType.rename, ih] | 4 | 21 | false | Type systems |
95 | Capless.Context.cvar_bound_cvar_inst_inv' | theorem Context.cvar_bound_cvar_inst_inv' {Γ : Context n m k}
(he1 : Γ' = Context.cvar Γ (CBinding.bound b0))
(he2 : b' = CBinding.inst C)
(hb : Context.CBound Γ' c b') :
∃ c0 C0, c = c0.succ ∧ C = C0.cweaken ∧ Context.CBound Γ c0 (CBinding.inst C0) | capless-lean | Capless/Context.lean | [
"import Capless.Type",
"import Capless.CaptureSet"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [
{
"name": "Capless.TBinding",
"content": "inductive TBinding : Nat -> Nat -> Nat -> Type where\n| bound : SType n m k -> TBinding n m k\n| inst : SType n m k -> TBinding n m k"
},
{
"name": "Capless.CBinding",
"content": "inductive CBinding : Nat -> Nat -> Type where\n| bound : CBound n k -> CBi... | [
{
"name": "Capless.CBinding.eq_inst_cweaken_inv",
"content": "theorem CBinding.eq_inst_cweaken_inv {b : CBinding n k}\n (h : CBinding.inst C = b.cweaken) :\n ∃ C0, b = CBinding.inst C0"
}
] | import Capless.Type
import Capless.CaptureSet
namespace Capless
inductive TBinding : Nat -> Nat -> Nat -> Type where
| bound : SType n m k -> TBinding n m k
| inst : SType n m k -> TBinding n m k
inductive CBinding : Nat -> Nat -> Type where
| bound : CBound n k -> CBinding n k
| inst : CaptureSet n k -> CBinding n k
inductive Context : Nat -> Nat -> Nat -> Type where
| empty : Context 0 0 0
| var : Context n m k -> CType n m k -> Context (n+1) m k
| label : Context n m k -> SType n m k -> Context (n+1) m k
| tvar : Context n m k -> TBinding n m k -> Context n (m+1) k
| cvar : Context n m k -> CBinding n k -> Context n m (k+1)
notation:30 Γ ",x:" T => Context.var Γ T
notation:30 Γ ",X<:" T => Context.tvar Γ (TBinding.bound T)
notation:30 Γ ",X:=" T => Context.tvar Γ (TBinding.inst T)
notation:30 Γ ",c<:" B => Context.cvar Γ (CBinding.bound B)
notation:30 Γ ",c<:*" => Context.cvar Γ (CBinding.bound CBound.star)
notation:30 Γ ",c:=" C => Context.cvar Γ (CBinding.inst C)
def TBinding.crename (b : TBinding n m k) (f : FinFun k k') : TBinding n m k' :=
match b with
| bound S => bound (S.crename f)
| inst S => inst (S.crename f)
def CBinding.crename (b : CBinding n k) (f : FinFun k k') : CBinding n k' :=
match b with
| bound b0 => bound (b0.crename f)
| inst C => inst (C.crename f)
def TBinding.cweaken (b : TBinding n m k) : TBinding n m (k+1) :=
b.crename FinFun.weaken
def CBinding.cweaken (b : CBinding n k) : CBinding n (k+1) :=
b.crename FinFun.weaken
inductive Context.CBound : Context n m k -> Fin k -> CBinding n k -> Prop where
| here : CBound (cvar Γ0 b) 0 b.cweaken
| there_var :
CBound Γ x b ->
CBound (var Γ E) x b.weaken
| there_tvar :
CBound Γ x b ->
CBound (tvar Γ b') x b
| there_cvar :
CBound Γ x b ->
CBound (cvar Γ b') (Fin.succ x) b.cweaken
| there_label :
CBound Γ x b ->
CBound (label Γ S) x b.weaken
inductive Context.LBound : Context n m k -> Fin n -> SType n m k -> Prop where
| here : LBound (label Γ0 S) 0 S.weaken
| there_var :
LBound Γ x S ->
LBound (var Γ E) x.succ S.weaken
| there_tvar :
LBound Γ x S ->
LBound (tvar Γ b) x S.tweaken
| there_cvar :
LBound Γ x S ->
LBound (cvar Γ b) x S.cweaken
| there_label :
LBound Γ x S ->
LBound (label Γ S') x.succ S.weaken | theorem Context.cvar_bound_cvar_inst_inv' {Γ : Context n m k}
(he1 : Γ' = Context.cvar Γ (CBinding.bound b0))
(he2 : b' = CBinding.inst C)
(hb : Context.CBound Γ' c b') :
∃ c0 C0, c = c0.succ ∧ C = C0.cweaken ∧ Context.CBound Γ c0 (CBinding.inst C0) := | := by
cases hb <;> try (solve | cases he1)
case here =>
have h := CBinding.eq_inst_cweaken_inv (Eq.symm he2)
have ⟨C0, h⟩ := h
subst h; cases he1
case there_cvar =>
have ⟨C0, h⟩ := CBinding.eq_inst_cweaken_inv (Eq.symm he2)
subst h; simp [CBinding.cweaken, CBinding.crename] at he2
rename_i x0 _ _ _
exists x0, C0; simp [CaptureSet.cweaken]; aesop | 3 | 32 | false | Type systems |
96 | Capless.SType.crename_crename | theorem SType.crename_crename (S : SType n m k) (f : FinFun k k') (g : FinFun k' k'') :
(S.crename f).crename g = S.crename (g ∘ f) :=
match S with
| SType.top => by simp [SType.crename]
| SType.tvar X => by simp [SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_crename E1 f g
have ih2 := EType.crename_crename E2 f g
simp [SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_crename S f g
have ih2 := EType.crename_crename E f g
simp [SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_crename E f.ext g.ext
simp [SType.crename, ih, FinFun.ext_comp_ext, CBound.crename_crename]
| SType.box T => by
have ih := CType.crename_crename T f g
simp [SType.crename, ih]
| SType.label S => by
have ih := SType.crename_crename S f g
simp [SType.crename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Basic",
"import Capless.Type.Renaming",
"import Capless.Type.Core",
"import Capless.CaptureSet"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.crename_crename",
"content": "theorem CaptureSet.crename_crename {C : CaptureSet n k} :\n (C.crename f).crename g = C.crename (g ∘ f)"
},
{
"name": "FinFun.ext_comp_ext",
"content": "theorem FinFun.ext_comp_ext {f : FinFun n n'} {g : FinFun n' n''} :\n g.ext ∘ f.ext = Fin... | [] | [
{
"name": "Capless.CBound.crename_crename",
"content": "theorem CBound.crename_crename {b : CBound n k} :\n (b.crename f).crename g = b.crename (g ∘ f)"
},
{
"name": "Capless.EType.crename_crename",
"content": "theorem EType.crename_crename (E : EType n m k) (f : FinFun k k') (g : FinFun k' k''... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end
end | theorem SType.crename_crename (S : SType n m k) (f : FinFun k k') (g : FinFun k' k'') :
(S.crename f).crename g = S.crename (g ∘ f) := | :=
match S with
| SType.top => by simp [SType.crename]
| SType.tvar X => by simp [SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_crename E1 f g
have ih2 := EType.crename_crename E2 f g
simp [SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_crename S f g
have ih2 := EType.crename_crename E f g
simp [SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_crename E f.ext g.ext
simp [SType.crename, ih, FinFun.ext_comp_ext, CBound.crename_crename]
| SType.box T => by
have ih := CType.crename_crename T f g
simp [SType.crename, ih]
| SType.label S => by
have ih := SType.crename_crename S f g
simp [SType.crename, ih] | 4 | 20 | false | Type systems |
97 | Capless.SType.crename_trename_comm | theorem SType.crename_trename_comm (S : SType n m k) (f : FinFun k k') (g : FinFun m m') :
(S.crename f).trename g = (S.trename g).crename f :=
match S with
| SType.top => by simp [SType.crename, SType.trename]
| SType.tvar X => by simp [SType.crename, SType.trename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_trename_comm E1 f g
have ih2 := EType.crename_trename_comm E2 f g
simp [SType.crename, SType.trename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_trename_comm S f g
have ih2 := EType.crename_trename_comm E f g.ext
simp [SType.crename, SType.trename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_trename_comm E f.ext g
simp [SType.crename, SType.trename, ih]
| SType.box T => by
have ih := CType.crename_trename_comm T f g
simp [SType.crename, SType.trename, ih]
| SType.label S => by
have ih := SType.crename_trename_comm S f g
simp [SType.crename, SType.trename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Type.Renaming",
"import Capless.Type.Core"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "List.getElem_append_left{α",
"content": "theorem List.getElem_append_left{α : Type u_1} {l₁ l₂ : List α} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ l₂)[i] = l₁[i]"
}
] | [] | [
{
"name": "Capless.EType.crename_trename_comm",
"content": "theorem EType.crename_trename_comm (E : EType n m k) (f : FinFun k k') (g : FinFun m m') :\n (E.crename f).trename g = (E.trename g).crename f"
},
{
"name": "Capless.CType.crename_trename_comm",
"content": "theorem CType.crename_trenam... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end
end
end | theorem SType.crename_trename_comm (S : SType n m k) (f : FinFun k k') (g : FinFun m m') :
(S.crename f).trename g = (S.trename g).crename f := | :=
match S with
| SType.top => by simp [SType.crename, SType.trename]
| SType.tvar X => by simp [SType.crename, SType.trename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_trename_comm E1 f g
have ih2 := EType.crename_trename_comm E2 f g
simp [SType.crename, SType.trename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_trename_comm S f g
have ih2 := EType.crename_trename_comm E f g.ext
simp [SType.crename, SType.trename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_trename_comm E f.ext g
simp [SType.crename, SType.trename, ih]
| SType.box T => by
have ih := CType.crename_trename_comm T f g
simp [SType.crename, SType.trename, ih]
| SType.label S => by
have ih := SType.crename_trename_comm S f g
simp [SType.crename, SType.trename, ih] | 3 | 20 | false | Type systems |
98 | Capless.SType.crename_id | theorem SType.crename_id {S : SType n m k} :
S.crename FinFun.id = S :=
match S with
| SType.top => by simp [SType.crename]
| SType.tvar X => by simp [SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_id (T := E1)
have ih2 := EType.crename_id (E := E2)
simp [SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_id (S := S)
have ih2 := EType.crename_id (E := E)
simp [SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_id (E := E)
simp [SType.crename, CBound.crename_id, FinFun.id_ext, ih]
| SType.box T => by
have ih := CType.crename_id (T := T)
simp [SType.crename, ih]
| SType.label S => by
have ih := SType.crename_id (S := S)
simp [SType.crename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Basic",
"import Capless.Type.Renaming",
"import Capless.Type.Core",
"import Capless.CaptureSet"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "CaptureSet.crename_id",
"content": "theorem CaptureSet.crename_id {C : CaptureSet n k} :\n C.crename FinFun.id = C"
},
{
"name": "FinFun.id_ext",
"content": "theorem FinFun.id_ext :\n (FinFun.ext (n := n) id) = id"
}
] | [] | [
{
"name": "Capless.CBound.crename_id",
"content": "theorem CBound.crename_id {b : CBound n k} :\n b.crename FinFun.id = b"
},
{
"name": "Capless.EType.crename_id",
"content": "theorem EType.crename_id {E : EType n m k} :\n E.crename FinFun.id = E"
},
{
"name": "Capless.CType.crename_id... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end
end
end
end
end
end
end | theorem SType.crename_id {S : SType n m k} :
S.crename FinFun.id = S := | :=
match S with
| SType.top => by simp [SType.crename]
| SType.tvar X => by simp [SType.crename]
| SType.forall E1 E2 => by
have ih1 := CType.crename_id (T := E1)
have ih2 := EType.crename_id (E := E2)
simp [SType.crename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.crename_id (S := S)
have ih2 := EType.crename_id (E := E)
simp [SType.crename, ih1, ih2]
| SType.cforall B E => by
have ih := EType.crename_id (E := E)
simp [SType.crename, CBound.crename_id, FinFun.id_ext, ih]
| SType.box T => by
have ih := CType.crename_id (T := T)
simp [SType.crename, ih]
| SType.label S => by
have ih := SType.crename_id (S := S)
simp [SType.crename, ih] | 5 | 21 | false | Type systems |
99 | Capless.SType.trename_trename | theorem SType.trename_trename (S : SType n m k) (f : FinFun m m') (g : FinFun m' m'') :
(S.trename f).trename g = S.trename (g ∘ f) :=
match S with
| SType.top => by simp [SType.trename]
| SType.tvar X => by simp [SType.trename]
| SType.forall E1 E2 => by
have ih1 := CType.trename_trename E1 f g
have ih2 := EType.trename_trename E2 f g
simp [SType.trename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.trename_trename S f g
have ih2 := EType.trename_trename E f.ext g.ext
simp [SType.trename, ih1, ih2, FinFun.ext_comp_ext]
| SType.cforall B E => by
have ih := EType.trename_trename E f g
simp [SType.trename, ih]
| SType.box T => by
have ih := CType.trename_trename T f g
simp [SType.trename, ih]
| SType.label S => by
have ih := SType.trename_trename S f g
simp [SType.trename, ih] | capless-lean | Capless/Type/Basic.lean | [
"import Capless.Basic",
"import Capless.Type.Renaming",
"import Capless.Type.Core"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
}
] | [
{
"name": "SType",
"content": "inductive SType : Nat -> Nat -> Nat -> Type where\n| top : SType n m k\n| tvar : Fin m -> SType n m k\n| forall : CType n m k -> EType (n+1) m k -> SType n m k\n| tforall : SType n m k -> EType n (m+1) k -> SType n m k\n| cforall : CBound n k -> EType n m (k+1) -> SType n m k\... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "FinFun.ext_comp_ext",
"content": "theorem FinFun.ext_comp_ext {f : FinFun n n'} {g : FinFun n' n''} :\n g.ext ∘ f.ext = FinFun.ext (g ∘ f)"
}
] | [] | [
{
"name": "Capless.EType.trename_trename",
"content": "theorem EType.trename_trename (E : EType n m k) (f : FinFun m m') (g : FinFun m' m'') :\n (E.trename f).trename g = E.trename (g ∘ f)"
},
{
"name": "Capless.CType.trename_trename",
"content": "theorem CType.trename_trename (T : CType n m k)... | import Capless.Type.Core
import Capless.Type.Renaming
namespace Capless
end
end
end
end
end | theorem SType.trename_trename (S : SType n m k) (f : FinFun m m') (g : FinFun m' m'') :
(S.trename f).trename g = S.trename (g ∘ f) := | :=
match S with
| SType.top => by simp [SType.trename]
| SType.tvar X => by simp [SType.trename]
| SType.forall E1 E2 => by
have ih1 := CType.trename_trename E1 f g
have ih2 := EType.trename_trename E2 f g
simp [SType.trename, ih1, ih2]
| SType.tforall S E => by
have ih1 := SType.trename_trename S f g
have ih2 := EType.trename_trename E f.ext g.ext
simp [SType.trename, ih1, ih2, FinFun.ext_comp_ext]
| SType.cforall B E => by
have ih := EType.trename_trename E f g
simp [SType.trename, ih]
| SType.box T => by
have ih := CType.trename_trename T f g
simp [SType.trename, ih]
| SType.label S => by
have ih := SType.trename_trename S f g
simp [SType.trename, ih] | 4 | 15 | false | Type systems |
100 | Capless.Typed.letex_inv' | theorem Typed.letex_inv' {Γ : Context n m k}
(he : t0 = Term.letex t u)
(h : Typed Γ t0 E Ct0) :
∃ T E0,
Typed Γ t (EType.ex T) Ct0 ∧
Typed ((Γ.cvar (CBinding.bound CBound.star)).var T) u E0.cweaken.weaken Ct0.cweaken.weaken ∧
ESubtyp Γ E0 E | capless-lean | Capless/Inversion/Typing.lean | [
"import Capless.Subcapturing.Basic",
"import Capless.Tactics",
"import Capless.Typing",
"import Capless.Subtyping.Basic",
"import Capless.Weakening.Typing",
"import Capless.Weakening.Subtyping",
"import Capless.Inversion.Subtyping",
"import Capless.Narrowing",
"import Capless.Weakening.Subcapturing"... | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.succ",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Exists",
"module": "Init.Core"
}
] | [
{
"name": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x",
"content": "notation:max \"{x=\" x \"}\" => CaptureSet.singleton x"
},
{
"name": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c",
"content": "notation:max \"{c=\" c \"}\" => CaptureSet.csingleton c"
},
{
"name"... | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "ESubtyp.cweaken",
"content": "theorem ESubtyp.cweaken\n (h : ESubtyp Γ E1 E2) :\n ESubtyp (Γ.cvar b) E1.cweaken E2.cweaken"
},
{
"name": "CSubtyp.weaken",
"content": "theorem CSubtyp.weaken\n (h : CSubtyp Γ E1 E2) :\n CSubtyp (Γ.var T) E1.weaken E2.weaken"
},
{
"name": "SS... | [] | [] | import Capless.Tactics
import Capless.Typing
import Capless.Subtyping.Basic
import Capless.Subcapturing.Basic
import Capless.Narrowing
import Capless.Weakening.Subcapturing
import Capless.Inversion.Context
import Capless.Inversion.Subtyping
namespace Capless | theorem Typed.letex_inv' {Γ : Context n m k}
(he : t0 = Term.letex t u)
(h : Typed Γ t0 E Ct0) :
∃ T E0,
Typed Γ t (EType.ex T) Ct0 ∧
Typed ((Γ.cvar (CBinding.bound CBound.star)).var T) u E0.cweaken.weaken Ct0.cweaken.weaken ∧
ESubtyp Γ E0 E := | := by
induction h <;> try (solve | cases he)
case letex =>
cases he
repeat apply Exists.intro
constructor; trivial
constructor; trivial
apply ESubtyp.refl
case sub hs ih =>
have ih := ih he
obtain ⟨T, E0, ht, hu, hs0⟩ := ih
have hs1 := ESubtyp.trans hs0 hs
repeat apply Exists.intro
repeat any_goals apply And.intro
{ apply Typed.sub
easy
easy
apply ESubtyp.refl }
{ apply Typed.sub
easy
apply Subcapt.weaken; apply Subcapt.cweaken; easy
apply ESubtyp.refl }
{ easy } | 3 | 92 | false | Type systems |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.