File size: 4,059 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | 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
|