math / data /lean /OAI /Algebra /DepthFive /Basic.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.06 kB
import Mathlib
namespace OAI
noncomputable section
open scoped BigOperators
universe u
namespace Problem335
inductive D5Leaf (K : Type u) (n : β„•) where
| scalar : K β†’ D5Leaf K n
| variable : (Fin n Γ— Fin n Γ— Fin n) β†’ D5Leaf K n
def d5LeafDegree {K : Type u} {n : β„•} : D5Leaf K n β†’ β„•
| D5Leaf.scalar _ => 0
| D5Leaf.variable _ => 1
structure Depth5Circuit (K : Type u) [CommSemiring K] (n : β„•) where
leafCount : β„•
leaves : Fin leafCount β†’ D5Leaf K n
bottomCount : β„•
bottomInputs : Fin bottomCount β†’ List (K Γ— Fin leafCount)
bottomDegree : Fin bottomCount β†’ β„•
bottomHomogeneous :
βˆ€ i entry, entry ∈ bottomInputs i β†’ d5LeafDegree (leaves entry.2) = bottomDegree i
bottomEmpty :
βˆ€ i, bottomInputs i = [] β†’ bottomDegree i = 0
lowerCount : β„•
lowerInputs : Fin lowerCount β†’ List (Fin bottomCount)
middleCount : β„•
middleInputs : Fin middleCount β†’ List (K Γ— Fin lowerCount)
middleDegree : Fin middleCount β†’ β„•
middleHomogeneous :
βˆ€ i entry, entry ∈ middleInputs i β†’
((lowerInputs entry.2).map bottomDegree).sum = middleDegree i
middleEmpty :
βˆ€ i, middleInputs i = [] β†’ middleDegree i = 0
upperCount : β„•
upperInputs : Fin upperCount β†’ List (Fin middleCount)
outputInputs : List (K Γ— Fin upperCount)
outputDegree : β„•
outputHomogeneous :
βˆ€ entry, entry ∈ outputInputs β†’
((upperInputs entry.2).map middleDegree).sum = outputDegree
outputEmpty :
outputInputs = [] β†’ outputDegree = 0
def d5LeafValue {K : Type u} [CommSemiring K] {n : β„•}
(x : D5Leaf K n) : MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K :=
match x with
| D5Leaf.scalar a => MvPolynomial.C a
| D5Leaf.variable i => MvPolynomial.X i
def bottomValue {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) (i : Fin c.bottomCount) :
MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
exact ((c.bottomInputs i).map (fun entry =>
MvPolynomial.C entry.1 * d5LeafValue (c.leaves entry.2))).sum
def lowerValue {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) (i : Fin c.lowerCount) :
MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
exact ((c.lowerInputs i).map (fun j => bottomValue c j)).prod
def middleValue {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) (i : Fin c.middleCount) :
MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
exact ((c.middleInputs i).map (fun entry =>
MvPolynomial.C entry.1 * lowerValue c entry.2)).sum
def upperValue {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) (i : Fin c.upperCount) :
MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
exact ((c.upperInputs i).map (fun j => middleValue c j)).prod
def circuitValue {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) : MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
exact (c.outputInputs.map (fun entry =>
MvPolynomial.C entry.1 * upperValue c entry.2)).sum
def circuitSize {K : Type u} [CommSemiring K] {n : β„•}
(c : Depth5Circuit K n) : β„• :=
c.leafCount + c.bottomCount + c.lowerCount + c.middleCount + c.upperCount + 1
def immLayer (K : Type u) [CommSemiring K] (n : β„•) (t : Fin n) :
Matrix (Fin n) (Fin n) (MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K) :=
fun i j => MvPolynomial.X (t, i, j)
def imm (K : Type u) [CommSemiring K] (n : β„•) :
MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K := by
classical
by_cases h : 0 < n
Β· let matrices :
List (Matrix (Fin n) (Fin n)
(MvPolynomial (Fin n Γ— Fin n Γ— Fin n) K)) :=
List.ofFn (fun t : Fin n => immLayer K n t)
exact matrices.prod ⟨0, h⟩ ⟨0, h⟩
Β· exact 0
def ceilSqrt (n : β„•) : β„• :=
Nat.sqrt n + if (Nat.sqrt n) ^ 2 = n then 0 else 1
def ceilDiv (n t : β„•) : β„• :=
(n + t - 1) / t
def upperGateBound (n : β„•) : β„• :=
let t := ceilSqrt n
let r := ceilDiv n t
2 * n ^ 3 + r * n ^ 2 + r * n ^ (t + 1) + n ^ (r - 1) + 1
end Problem335
end
end OAI