diff --git a/Complexity/Computability/Circuit/Approximation.lean b/Complexity/Computability/Circuit/Approximation.lean index 4102c09a1..215400d0a 100644 --- a/Complexity/Computability/Circuit/Approximation.lean +++ b/Complexity/Computability/Circuit/Approximation.lean @@ -92,7 +92,7 @@ def programExceptions : ∀ {g : ℕ}, Program σ n g → Finset Sample rfl /-- There are at most as many exceptions as the total cost of the gates. -/ -theorem card_programExceptions_le {g : ℕ} (p : Program σ n g) : +private theorem card_programExceptions_le {g : ℕ} (p : Program σ n g) : (S.programExceptions p).card ≤ p.cost S.errorCost := by induction p with | empty => simp @@ -123,7 +123,7 @@ theorem program_correct {g : ℕ} (p : Program σ n g) {s : Sample} | castSucc w => simpa only [Program.trace_gate_castSucc] using ih hs.1 w /-- Away from the exceptions, every output of a circuit is correct. -/ -theorem circuit_correct {m : ℕ} (C : Circuit σ n m) (o : Fin m) {s : Sample} +private theorem circuit_correct {m : ℕ} (C : Circuit σ n m) (o : Fin m) {s : Sample} (hs : s ∉ S.programExceptions C.program) : S.relation (C.eval exact (exactInput s) o) (decode (C.eval approx approxInput o) s) := S.program_correct C.program hs (C.outputs o) diff --git a/Complexity/Computability/Circuit/Arithmetic/Power.lean b/Complexity/Computability/Circuit/Arithmetic/Power.lean index 6c0e21989..481ab35b9 100644 --- a/Complexity/Computability/Circuit/Arithmetic/Power.lean +++ b/Complexity/Computability/Circuit/Arithmetic/Power.lean @@ -114,7 +114,7 @@ private theorem binaryPowerCircuit_bit (one : C) (bit : Bool) (e : ℕ) (he : e @[simp] theorem binaryMultiplicationCount_one : binaryMultiplicationCount 1 = 0 := by simp [binaryMultiplicationCount] -theorem binaryMultiplicationCount_bit (bit : Bool) (e : ℕ) (he : e ≠ 0) : +private theorem binaryMultiplicationCount_bit (bit : Bool) (e : ℕ) (he : e ≠ 0) : binaryMultiplicationCount (Nat.bit bit e) = binaryMultiplicationCount e + 1 + bit.toNat := Nat.binaryRecFromOne_eq bit e he diff --git a/Complexity/Computability/Circuit/Arithmetic/VNP.lean b/Complexity/Computability/Circuit/Arithmetic/VNP.lean index 0a6111900..ad57b7ece 100644 --- a/Complexity/Computability/Circuit/Arithmetic/VNP.lean +++ b/Complexity/Computability/Circuit/Arithmetic/VNP.lean @@ -82,12 +82,12 @@ noncomputable def booleanSum (m : ℕ) (P : MvPolynomial (Fin (n + m)) K) : /-- Lift a projection of the first `k` of `k + m` variables to all of them, keeping the last `m` variables. -/ -def liftProjection (ρ : Fin k → Fin n ⊕ K) : Fin (k + m) → Fin (n + m) ⊕ K := +private def liftProjection (ρ : Fin k → Fin n ⊕ K) : Fin (k + m) → Fin (n + m) ⊕ K := Fin.append (fun i => (ρ i).map (Fin.castAdd m) id) fun i => Sum.inl (Fin.natAdd n i) /-- A projection of a Boolean sum is the Boolean sum of a projection: substitution for the first variables commutes with summing over the last. -/ -theorem projection_booleanSum (ρ : Fin k → Fin n ⊕ K) (P : MvPolynomial (Fin (k + m)) K) : +private theorem projection_booleanSum (ρ : Fin k → Fin n ⊕ K) (P : MvPolynomial (Fin (k + m)) K) : projection ρ (booleanSum m P) = booleanSum m (projection (liftProjection ρ) P) := by rw [booleanSum, booleanSum, map_sum] refine Finset.sum_congr rfl fun e _ => ?_ @@ -101,7 +101,7 @@ theorem projection_booleanSum (ρ : Fin k → Fin n ⊕ K) (P : MvPolynomial (Fi | right i => cases e i <;> simp [booleanAssignment, liftProjection] /-- A Boolean sum has no larger degree than the summed polynomial. -/ -theorem totalDegree_booleanSum_le (P : MvPolynomial (Fin (n + m)) K) : +private theorem totalDegree_booleanSum_le (P : MvPolynomial (Fin (n + m)) K) : (booleanSum m P).totalDegree ≤ P.totalDegree := totalDegree_finsetSum_le fun _ _ => totalDegree_projection_le _ _ diff --git a/Complexity/Computability/Circuit/Arithmetic/VP.lean b/Complexity/Computability/Circuit/Arithmetic/VP.lean index a4b42ebab..e848e2105 100644 --- a/Complexity/Computability/Circuit/Arithmetic/VP.lean +++ b/Complexity/Computability/Circuit/Arithmetic/VP.lean @@ -121,7 +121,8 @@ theorem Circuit.aeval_polynomial {R : Type*} [CommSemiring R] [Algebra K R] /-- Substituting polynomials for the variables of the polynomial computed by a circuit is evaluating the circuit at those polynomials. -/ -theorem Circuit.aeval_polynomial_mvPolynomial {σ : Type*} (c : Circuit (arithSignature K) n m) +private theorem Circuit.aeval_polynomial_mvPolynomial {σ : Type*} + (c : Circuit (arithSignature K) n m) (x : Fin n → MvPolynomial σ K) (j : Fin m) : aeval x (c.polynomial j) = c.eval (arithInterpretationWith K C) x j := by rw [c.aeval_polynomial, algebraMap_eq] @@ -320,7 +321,7 @@ theorem size_projectionCircuit_le (ρ : Fin m → Fin n ⊕ K) : (projectionCirc /-- Feeding the substitution of a projection to a circuit computes the projection of its polynomial. -/ -theorem polynomial_comp_projectionCircuit (c : Circuit (arithSignature K) m p) +private theorem polynomial_comp_projectionCircuit (c : Circuit (arithSignature K) m p) (ρ : Fin m → Fin n ⊕ K) (j : Fin p) : (c.comp (projectionCircuit ρ)).polynomial j = projection ρ (c.polynomial j) := by rw [projection, Circuit.aeval_polynomial_mvPolynomial, Circuit.polynomial, Circuit.eval_comp] diff --git a/Complexity/Computability/Circuit/Arithmetic/Waring/Compilation.lean b/Complexity/Computability/Circuit/Arithmetic/Waring/Compilation.lean index 6e8b32c53..af05db44f 100644 --- a/Complexity/Computability/Circuit/Arithmetic/Waring/Compilation.lean +++ b/Complexity/Computability/Circuit/Arithmetic/Waring/Compilation.lean @@ -77,7 +77,7 @@ theorem Term.eval_toCircuit [Semiring R] (zero one : C) (constant : C → R) rfl /-- Exact weighted term cost, including all coefficient and zero/one constants. -/ -theorem Term.cost_program_toCircuit (zero one : C) (weight : ArithOp C → ℕ) (t : Term C d) : +private theorem Term.cost_program_toCircuit (zero one : C) (weight : ArithOp C → ℕ) (t : Term C d) : (t.toCircuit zero one).program.cost weight = weight (.const zero) + (∑ i, (weight (.const (t.coefficients i)) + weight .mul + weight .add)) + @@ -92,13 +92,13 @@ theorem Term.cost_program_toCircuit (zero one : C) (weight : ArithOp C → ℕ) def termMultiplicationCount (d : ℕ) : ℕ := d + binaryMultiplicationCount d + 1 /-- Exact term multiplication count, including the final scale multiplication at degree zero. -/ -theorem Term.mulCost_toCircuit (zero one : C) (t : Term C d) : +private theorem Term.mulCost_toCircuit (zero one : C) (t : Term C d) : (t.toCircuit zero one).program.cost ArithOp.mulCost = termMultiplicationCount d := by rw [Term.cost_program_toCircuit] by_cases hd : d = 0 <;> simp [ArithOp.mulCost, termMultiplicationCount, hd] /-- There is one linear-form addition per variable, including the initial addition to zero. -/ -theorem Term.addCost_toCircuit (zero one : C) (t : Term C d) : +private theorem Term.addCost_toCircuit (zero one : C) (t : Term C d) : (t.toCircuit zero one).program.cost ArithOp.addCost = d := by rw [Term.cost_program_toCircuit] simp [ArithOp.addCost] @@ -181,7 +181,7 @@ theorem cost_program_compile (zero one : C) | term t => exact t.cost_program_toCircuit zero one weight /-- Uniform term costs separate the total charge into source additions and term gates. -/ -theorem cost_program_compile_of_termCost (zero one : C) +private theorem cost_program_compile_of_termCost (zero one : C) (c : Circuit (SumOfTerms.signature (Term C d)) n m) (weight : ArithOp C → ℕ) {term : ℕ} (hterm : ∀ t : Term C d, (t.toCircuit zero one).program.cost weight = term) : (compile zero one c).program.cost weight = diff --git a/Complexity/Computability/Circuit/Boolean/ACC0.lean b/Complexity/Computability/Circuit/Boolean/ACC0.lean index 0fdd9ed78..2317e4402 100644 --- a/Complexity/Computability/Circuit/Boolean/ACC0.lean +++ b/Complexity/Computability/Circuit/Boolean/ACC0.lean @@ -73,7 +73,7 @@ namespace Cslib.Circuits.Boolean open Set Finset BitString Unbounded Cslib.Complexity Turing.MultiTapeTM /-- Folding `xor` over a Boolean word computes `parity` of its slice. -/ -theorem foldl_bne_eq_parity (w : List Bool) : +private theorem foldl_bne_eq_parity (w : List Bool) : w.foldl bne false = parity w.length (fun i => w[i]) := by have hcount : w.foldl bne false = decide (w.count true % 2 = 1) := by have hgen (b : Bool) (l : List Bool) : diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser.lean index 52e230c63..06802017e 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser.lean @@ -115,7 +115,7 @@ theorem initialState_valid {C : Circuit (fullSignature 2 Bool) n 1} theorem initialState_a (C : Circuit (fullSignature 2 Bool) n 1) : (initialState C).a = n := by simp [State.a, State.m, State.q, initialState] -theorem initialState_W_le (C : Circuit (fullSignature 2 Bool) n 1) : +private theorem initialState_W_le (C : Circuit (fullSignature 2 Bool) n 1) : (initialState C).W ≤ 2 * C.size + 7 * n := by have hs : (initialState C).s = C.size := by simp [State.s, SemiCircuit.size, initialState] diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Deletion.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Deletion.lean index 603adaea9..a1bc43f3e 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Deletion.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Deletion.lean @@ -153,7 +153,7 @@ theorem Valid.unit_delete {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAffin exact ⟨S', hS', hm, hs, ha', hq, by omega⟩ /-- (D4) as a step of gate elimination. -/ -theorem Valid.step_unit {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAffineDisperser f d) +private theorem Valid.step_unit {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAffineDisperser f d) (ha : d < S.a) {x e : ℕ} (hx : x ∈ S.unpaired) (hc : S.children x = {.inr e}) : ∃ S', Step f S S' := by obtain ⟨S', hS', hm, hs, ha', -, hW⟩ := hS.unit_delete hf ha hx hc diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Elimination.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Elimination.lean index 96bf21409..ade796a89 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Elimination.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Elimination.lean @@ -64,7 +64,7 @@ def SharedSecondChild (S : State n) (G x y : ℕ) : Prop := /-- Restricting one input `x'` of the minimal AND and deleting its two children `G` and `B`, which are also the children of the other input `y'`, is a step: `Δa = -1`, `ΔW ≤ -18`. -/ -theorem Reduction.step_of_shared {S S' : State n} (hS : S.Valid f) {G x' y' : ℕ} +private theorem Reduction.step_of_shared {S S' : State n} (hS : S.Valid f) {G x' y' : ℕ} {B : ℕ ⊕ ℕ} (hx' : x' ∈ S.unpaired) (hy' : y' ∈ S.unpaired) (hxy : x' ≠ y') (hx'2 : S.deg x' = 2) (hy'2 : S.deg y' = 2) (hcy : S.children y' = {.inl G, B}) (h : Reduction f S S' {x'} [.inl G, B] []) : Step f S S' := by @@ -90,7 +90,7 @@ theorem Reduction.step_of_shared {S S' : State n} (hS : S.Valid f) {G x' y' : /-- Restricting a parameter `x'` to a constant or to a literal of another parameter with at least its children, on which the gates `G` and `B ≠ G`, `B` not reading `G`, are constant, and deleting both gates, is a reduction. -/ -theorem Valid.exists_reduction_restrict_deleteConst {S : State n} (hS : S.Valid f) {x' : ℕ} +private theorem Valid.exists_reduction_restrict_deleteConst {S : State n} (hS : S.Valid f) {x' : ℕ} (hx' : x' ∈ S.params) {ℓ : Lit} (hℓ : ∀ t, ℓ.Reads t → t ∈ S.params ∧ t ≠ x' ∧ S.children x' ⊆ S.children t ∧ (S.Paired x' → S.IsPartner x' t)) {G B : ℕ} (hG : G ∈ S.gates) (hB : B ∈ S.gates) (hBG : B ≠ G) @@ -114,7 +114,7 @@ theorem Valid.exists_reduction_restrict_deleteConst {S : State n} (hS : S.Valid /-- Case 7 when the shared second child `B` of `x` and `y` is a gate: on one of the lines `x = c`, `y = c` or `x = y + c` both `G` and `B` are constant, and restricting to it deletes both. -/ -theorem Valid.exists_reduction_sharedGate {S : State n} (hS : S.Valid f) {G x y B : ℕ} +private theorem Valid.exists_reduction_sharedGate {S : State n} (hS : S.Valid f) {G x y B : ℕ} (h : S.MinimalAnd G x y) (hcx : S.children x = {.inl G, .inl B}) (hcy : S.children y = {.inl G, .inl B}) (hBG : B ≠ G) : ∃ S' x' y', ((x' = x ∧ y' = y) ∨ (x' = y ∧ y' = x)) ∧ @@ -163,7 +163,7 @@ theorem Valid.exists_reduction_sharedGate {S : State n} (hS : S.Valid f) {G x y /-- Case 7 when the shared second child of `x` and `y` is an equation `v + x + y = rhs`: restricting to the line `x = y + c` on which `G` is constant makes the equation read `v = rhs + c`, and both are deleted. -/ -theorem Valid.exists_reduction_sharedEqn {S : State n} (hS : S.Valid f) (hN : S.Normal) +private theorem Valid.exists_reduction_sharedEqn {S : State n} (hS : S.Valid f) (hN : S.Normal) {G x y e : ℕ} (h : S.MinimalAnd G x y) (hcx : S.children x = {.inl G, .inr e}) (hcy : S.children y = {.inl G, .inr e}) : ∃ S', Reduction f S S' {x} [.inl G, .inr e] [] := by @@ -283,7 +283,7 @@ def fixInputDeleted (S : State n) (G x : ℕ) : Finset (ℕ ⊕ ℕ) := /-- Fixing the input `x` of the minimal AND so that `G` becomes constant, and deleting `G`, the other children of `x` and the children of `G`, is a reduction deleting `deg x + deg G` constraints. -/ -theorem Valid.exists_reduction_fixInput {S : State n} (hS : S.Valid f) {G x y : ℕ} +private theorem Valid.exists_reduction_fixInput {S : State n} (hS : S.Valid f) {G x y : ℕ} (h : S.MinimalAnd G x y) : ∃ S', Reduction f S S' {x} (.inl G :: (S.fixInputDeleted G x).toList) (S.fixInputDeleted G x).toList := by have hxG := h.ne_gate hS h.mem_params_x @@ -302,7 +302,7 @@ theorem Valid.exists_reduction_fixInput {S : State n} (hS : S.Valid f) {G x y : (by rw [fixConst_gate, Gate.reads_subst_of_ne hxG.symm (by simp [Lit.const])]; exact hKG) exact ⟨S', (h₁.trans_delete h₂).trans_delete h₃⟩ -theorem MinimalAnd.length_fixInput {S : State n} (hS : S.Valid f) {G x y : ℕ} +private theorem MinimalAnd.length_fixInput {S : State n} (hS : S.Valid f) {G x y : ℕ} (h : S.MinimalAnd G x y) : (Sum.inl G :: (S.fixInputDeleted G x).toList).length = S.deg x + S.deg G := by have hdisj : Disjoint ((S.children x).erase (.inl G)) (S.children G) := by @@ -378,7 +378,7 @@ theorem Reduction.wt_add_le_fixInput {S S' : State n} (hS : S.Valid f) (hN : S.N /-- Outside the bottleneck configuration, when `deg x = 2` and `G` has one child, no unpaired isolated parameter lies below `G`. -/ -theorem MinimalAnd.not_isolatedBelow {S : State n} (hS : S.Valid f) {G x y : ℕ} +private theorem MinimalAnd.not_isolatedBelow {S : State n} (hS : S.Valid f) {G x y : ℕ} (h : S.MinimalAnd G x y) (hbot : ¬ S.Bottleneck G x) (hx2 : S.deg x = 2) (hG1 : S.deg G = 1) {u : ℕ} : ¬ S.IsolatedBelow G u := fun ⟨hu1, hu2, N, hNG, hNu⟩ => by refine hbot ⟨hx2, ?_⟩ @@ -434,7 +434,7 @@ theorem Valid.step_fixInput {S : State n} (hS : S.Valid f) (hN : S.Normal) {G x /-- The weights after the quadratic reparameterisation: `x` and `y` become paired, `z` is replaced by `D`, which gains at most seven, and no other weight grows. -/ -theorem QuadOK.wt_add_le {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β γ c : Bool} +private theorem QuadOK.wt_add_le {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β γ c : Bool} (h : S.QuadOK x y z G D α β γ c) (hx : 2 ≤ S.deg x) (hy : 2 ≤ S.deg y) : ∀ u ∈ insert D S.params, (S.quad x y z G D α β γ c).wt u + ((if u = x then 7 else 0) + (if u = y then 7 else 0) + (if u = z then 6 else 0)) ≤ S.wt u + (if u = D then 7 else 0) := by @@ -484,7 +484,7 @@ theorem QuadOK.wt_add_le {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β /-- The quadratic reparameterisation of the bottleneck configuration, when `x` and `y` have degree at least two, is a step of gate elimination: `Δa = -1`, `ΔW ≤ -14`. -/ -theorem Valid.step_quad {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β γ c : Bool} +private theorem Valid.step_quad {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β γ c : Bool} (h : S.QuadOK x y z G D α β γ c) (hx : 2 ≤ S.deg x) (hy : 2 ≤ S.deg y) : Step f S (S.quad x y z G D α β γ c) := by set S' := S.quad x y z G D α β γ c @@ -509,7 +509,7 @@ theorem Valid.step_quad {S : State n} (hS : S.Valid f) {x y z G D : ℕ} {α β by simp only [State.a]; omega⟩ /-- In the bottleneck configuration, `G` has the unique child `D` and `z` the unique child `D`. -/ -theorem MinimalAnd.children_of_bottleneck {S : State n} (hS : S.Valid f) {G x y D z : ℕ} +private theorem MinimalAnd.children_of_bottleneck {S : State n} (hS : S.Valid f) {G x y D z : ℕ} (h : S.MinimalAnd G x y) (hDiff : ∀ K ∈ S.gates, (S.gate K).Reads G ↔ K = D) (hD : D ∈ S.gates) (hz1 : S.deg z = 1) (hDz : (S.gate D).Reads z) : S.children G = {.inl D} ∧ S.children z = {.inl D} := by @@ -527,7 +527,7 @@ theorem MinimalAnd.children_of_bottleneck {S : State n} (hS : S.Valid f) {G x y /-- In the bottleneck configuration with `D` AND-type, fixing `x` and `y` so that `G` takes the value making `D` constant deletes `G`, `D` and the second children `Bx`, `By` of `x` and `y`. -/ -theorem Valid.exists_reduction_bottleneck_and {S : State n} (hS : S.Valid f) {G x y D : ℕ} +private theorem Valid.exists_reduction_bottleneck_and {S : State n} (hS : S.Valid f) {G x y D : ℕ} (h : S.MinimalAnd G x y) (hD : D ∈ S.gates) (hDG' : D ≠ G) {δ c : Bool} (hc : ∀ val : ℕ → Bool, val G = δ → (S.gate D).eval val = c) {x₀ y₀ : Bool} (hδ : (S.gate G).eval (Function.update (Function.update (fun _ => false) y y₀) @@ -674,7 +674,7 @@ theorem Valid.step_of_bottleneck_xor {S : State n} {d : ℕ} (hS : S.Valid f) /-- **Cases 9 and 10** of [Mishra and Santhanam, Section 4.3][MishraSanthanam2026], the bottleneck configuration: the unique child `D` of the minimal AND `G` reads an unpaired isolated parameter `z`; its elimination is a step. -/ -theorem Valid.step_of_bottleneck {S : State n} {d : ℕ} (hS : S.Valid f) +private theorem Valid.step_of_bottleneck {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAffineDisperser f d) (ha : d < S.a) (hN : S.Normal) {G x y : ℕ} (h : S.MinimalAnd G x y) (h7 : ¬ S.SharedSecondChild G x y) (hbot : S.Bottleneck G x) : ∃ S', Step f S S' := by diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/MinimalAnd.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/MinimalAnd.lean index fd55fb577..8d57bfc13 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/MinimalAnd.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/MinimalAnd.lean @@ -62,7 +62,7 @@ variable {n : ℕ} {f : BooleanFunction n} /-- An auxiliary variable of a valid state occurs in some equation: otherwise the affine system would not determine it. -/ -theorem Valid.exists_eqn_of_aux {S : State n} (hS : S.Valid f) {v : ℕ} (hv : v ∈ S.aux) : +private theorem Valid.exists_eqn_of_aux {S : State n} (hS : S.Valid f) {v : ℕ} (hv : v ∈ S.aux) : ∃ e ∈ S.eqns, v ∈ (S.eqn e).terms := by by_contra hne push Not at hne @@ -79,7 +79,7 @@ theorem Valid.exists_eqn_of_aux {S : State n} (hS : S.Valid f) {v : ℕ} (hv : v /-- The affine reparameterisation of an unpaired parameter `x` of degree at least two and an auxiliary variable `Q` of degree at least two depending on it is a preparatory operation: it keeps every child, and both weights are `7`. -/ -theorem Valid.preparation_swap {S : State n} (hS : S.Valid f) {x Q : ℕ} {c : Bool} +private theorem Valid.preparation_swap {S : State n} (hS : S.Valid f) {x Q : ℕ} {c : Bool} {T : Finset ℕ} (hx : x ∈ S.unpaired) (hxdeg : 2 ≤ S.deg x) (hQ : Q ∈ S.aux) (hQdeg : 2 ≤ S.deg Q) (haff : S.AffineIn Q c T) (hxT : x ∈ T) : Preparation f S (S.swap x Q c T) := by @@ -129,7 +129,7 @@ theorem Valid.preparation_swap {S : State n} (hS : S.Valid f) {x Q : ℕ} {c : B /-- Rewiring a gate to a gate reading only parameters of degree at least two is a preparatory operation: only those parameters may gain a child, and their weight is already `7`. -/ -theorem Valid.preparation_rewire {S : State n} (hS : S.Valid f) {J : ℕ} {g : Gate} +private theorem Valid.preparation_rewire {S : State n} (hS : S.Valid f) {J : ℕ} {g : Gate} (h : S.RewireOK J g) (hdeg : ∀ t, g.Reads t → t ∈ S.unpaired → 2 ≤ S.deg t) : Preparation f S (S.rewire J g) := by refine ⟨hS.rewire h, rfl, rfl, rfl, ?_⟩ @@ -160,13 +160,14 @@ theorem Valid.preparation_rewire {S : State n} (hS : S.Valid f) {J : ℕ} {g : G /-! ### Degenerate minimal gates allow deletions -/ -theorem deletionAvailable_of_degenerate {S : State n} {J : ℕ} (hJ : J ∈ S.gates) +private theorem deletionAvailable_of_degenerate {S : State n} {J : ℕ} (hJ : J ∈ S.gates) (h : (S.gate J).Degenerate) : S.DeletionAvailable := Or.inr (Or.inl ⟨J, hJ, (S.gate J).lit, fun _ ht => Gate.reads_of_lit_reads ht, fun val _ => Gate.eval_lit h val⟩) /-- A gate one of whose inputs is constant on the solutions of the affine system allows (D1). -/ -theorem deletionAvailable_of_const_input {S : State n} {J t : ℕ} (hJ : J ∈ S.gates) {c : Bool} +private theorem deletionAvailable_of_const_input {S : State n} {J t : ℕ} (hJ : J ∈ S.gates) + {c : Bool} (ht : (S.gate J).Reads t) (hc : ∀ val, S.EqnsHold val → val t = c) : S.DeletionAvailable := by refine Or.inr (Or.inl ⟨J, hJ, ?_⟩) rcases ht with ht | ht @@ -183,7 +184,8 @@ theorem deletionAvailable_of_const_input {S : State n} {J t : ℕ} (hJ : J ∈ S /-- A gate whose inputs differ by a constant on the solutions of the affine system allows (D1). -/ -theorem deletionAvailable_of_dependent {S : State n} {J t t' : ℕ} (hJ : J ∈ S.gates) {c : Bool} +private theorem deletionAvailable_of_dependent {S : State n} {J t t' : ℕ} (hJ : J ∈ S.gates) + {c : Bool} (hargs : ((S.gate J).left = .node t ∧ (S.gate J).right = .node t') ∨ ((S.gate J).left = .node t' ∧ (S.gate J).right = .node t)) (hc : ∀ val, S.EqnsHold val → val t' = (val t ^^ c)) : S.DeletionAvailable := by @@ -203,7 +205,7 @@ theorem deletionAvailable_of_dependent {S : State n} {J t t' : ℕ} (hJ : J ∈ /-! ### The minimal gate of a normal state -/ /-- The output of a valid state with `d < a` is not a literal of an auxiliary variable. -/ -theorem Valid.not_out_reads_aux {S : State n} {d : ℕ} (hS : S.Valid f) +private theorem Valid.not_out_reads_aux {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAffineDisperser f d) (ha : d < S.a) {v : ℕ} (hv : v ∈ S.aux) : ¬ S.out.Reads v := by intro hr obtain ⟨c, T, hT⟩ := hS.wf.exists_affineIn hv @@ -258,7 +260,8 @@ theorem Valid.exists_minGate {S : State n} {d : ℕ} (hS : S.Valid f) (hf : IsAf /-- An auxiliary input `Q` of the minimal gate depends on a parameter `x` other than the other input; when no preliminary reduction applies, `x` is unpaired of degree at least two, and `Q` has degree at least two. -/ -theorem Valid.exists_param_of_aux_input {S : State n} (hS : S.Valid f) (hN : S.Normal) {G Q o : ℕ} +private theorem Valid.exists_param_of_aux_input {S : State n} (hS : S.Valid f) (hN : S.Normal) + {G Q o : ℕ} (hG : G ∈ S.gates) (hargs : ((S.gate G).left = .node Q ∧ (S.gate G).right = .node o) ∨ ((S.gate G).left = .node o ∧ (S.gate G).right = .node Q)) (hQ : Q ∈ S.aux) (hQo : Q ≠ o) : @@ -316,16 +319,16 @@ def childIn (S : State n) : ℕ := ∃ t ∈ S.params, (S.gate (S.gates.min' h)).Reads t ∧ (S.gate K).Reads t).card else 0 -theorem auxIn_eq {S : State n} (hne : S.gates.Nonempty) : +private theorem auxIn_eq {S : State n} (hne : S.gates.Nonempty) : S.auxIn = S.auxArgs (S.gate (S.gates.min' hne)) := by simp only [auxIn, dite_eq_left hne] -theorem auxArgs_nodes (S : State n) {g : Gate} {t₁ t₂ : ℕ} (hl : g.left = .node t₁) +private theorem auxArgs_nodes (S : State n) {g : Gate} {t₁ t₂ : ℕ} (hl : g.left = .node t₁) (hr : g.right = .node t₂) : S.auxArgs g = (if t₁ ∈ S.aux then 1 else 0) + (if t₂ ∈ S.aux then 1 else 0) := by simp only [auxArgs, hl, hr] -theorem childIn_eq {S : State n} (hne : S.gates.Nonempty) : +private theorem childIn_eq {S : State n} (hne : S.gates.Nonempty) : S.childIn = (S.gates.filter fun K => (S.gate K).Reads (S.gates.min' hne) ∧ ∃ t ∈ S.params, (S.gate (S.gates.min' hne)).Reads t ∧ (S.gate K).Reads t).card := by simp only [childIn, dite_eq_left hne] diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Normal.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Normal.lean index 6c298a078..976d4eb77 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Normal.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Normal.lean @@ -129,7 +129,7 @@ theorem Valid.step_of_andOnIsolated {S : State n} (hS : S.Valid f) (h : S.AndOnI /-- When Case 2 does not apply, an unpaired parameter read by an AND-type gate together with another parameter has degree at least two. -/ -theorem two_le_deg_of_not_andOnIsolated {S : State n} (h2 : ¬ S.AndOnIsolated) {G x y : ℕ} +private theorem two_le_deg_of_not_andOnIsolated {S : State n} (h2 : ¬ S.AndOnIsolated) {G x y : ℕ} (hG : G ∈ S.gates) (hand : ¬ IsAffineOp (S.gate G).op) (hargs : ((S.gate G).left = .node x ∧ (S.gate G).right = .node y) ∨ ((S.gate G).left = .node y ∧ (S.gate G).right = .node x)) @@ -208,7 +208,7 @@ theorem Valid.exclusive {S : State n} (hS : S.Valid f) (hmov : ∀ J, ¬ S.Movab def DegeneratePair (S : State n) : Prop := ∃ p ∈ S.params, S.Paired p ∧ (S.deg p = 0 ∨ 2 ≤ S.deg p) -theorem deg_eq_one_of_not_degeneratePair {S : State n} (h3 : ¬ S.DegeneratePair) {p : ℕ} +private theorem deg_eq_one_of_not_degeneratePair {S : State n} (h3 : ¬ S.DegeneratePair) {p : ℕ} (hp : p ∈ S.params) (hpp : S.Paired p) : S.deg p = 1 := by by_contra h exact h3 ⟨p, hp, hpp, by omega⟩ @@ -326,7 +326,7 @@ def PartnersShareChild (S : State n) : Prop := ∃ pr ∈ S.pairs, ∃ H, H ∈ S.children pr.1 ∧ H ∈ S.children pr.2 /-- When Case 4 does not apply, partners have no common child. -/ -theorem notMem_children_of_isPartner {S : State n} (h4 : ¬ S.PartnersShareChild) {p r : ℕ} +private theorem notMem_children_of_isPartner {S : State n} (h4 : ¬ S.PartnersShareChild) {p r : ℕ} (hpr : S.IsPartner p r) {N : ℕ ⊕ ℕ} (hNp : N ∈ S.children p) : N ∉ S.children r := fun hNr => by obtain ⟨pr, hpr', ⟨h1, h2⟩ | ⟨h1, h2⟩⟩ := hpr diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Operations.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Operations.lean index d528089cf..642bcace9 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Operations.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Operations.lean @@ -77,7 +77,7 @@ variable {n : ℕ} {f : BooleanFunction n} /-- A state with the parameters, pairs and parameter map of a valid state is valid when its semi-circuit is well formed and computes `f`. -/ -theorem Valid.of_phi {S S' : State n} (hS : S.Valid f) (hparams : S'.params = S.params) +private theorem Valid.of_phi {S S' : State n} (hS : S.Valid f) (hparams : S'.params = S.params) (hpairs : S'.pairs = S.pairs) (hphi : S'.phi = S.phi) (hwf : S'.WellFormed) (hcomp : ∀ val, S'.Consistent val → S'.out.eval val = f (S'.phi val)) : S'.Valid f where wf := hwf @@ -183,7 +183,7 @@ theorem restrict_size (S : State n) (x : ℕ) (ℓ : Lit) (P : Finset (ℕ × /-- Along an affine family on which the kept pairs are tame, the restricted family is affine and every pair is tame: a dropped pair has a constant member, or a constant sum when `x` is restricted to a literal of its partner. -/ -theorem RestrictOK.pairTame {S : State n} {x : ℕ} {ℓ : Lit} {P : Finset (ℕ × ℕ)} +private theorem RestrictOK.pairTame {S : State n} {x : ℕ} {ℓ : Lit} {P : Finset (ℕ × ℕ)} (h : S.RestrictOK x ℓ P) {k : ℕ} {τ : BitString k → ℕ → Bool} (htame : ∀ pr ∈ P, PairTame τ pr) : ∀ pr ∈ S.pairs, PairTame (fun u => Function.update (τ u) x (ℓ.eval (τ u))) pr := by diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reduction.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reduction.lean index abfe25ce1..bc660eb07 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reduction.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reduction.lean @@ -295,7 +295,7 @@ theorem wt_le (h : Reduction f S S' F D T) (hS : S.Valid f) {u : ℕ} · rw [h.wt_eq_zero hS hu hpart]; exact Nat.zero_le _ /-- A used parameter that is not the partner of a member of `F` gains at most one in weight. -/ -theorem wt_le_add_one (h : Reduction f S S' F D T) (hS : S.Valid f) {u : ℕ} +private theorem wt_le_add_one (h : Reduction f S S' F D T) (hS : S.Valid f) {u : ℕ} (hpart : ∀ x ∈ F, ¬ S.IsPartner x u) (hdeg : 1 ≤ S.deg u) : S'.wt u ≤ S.wt u + 1 := by by_cases hu : u ∈ S.unpaired · rw [wt_of_mem hu] @@ -453,7 +453,7 @@ restriction (UF) for an unpaired parameter and (PF) for a paired one. -/ def fixConst (S : State n) (w : ℕ) (b : Bool) : State n := S.restrict w (Lit.const b) (S.pairsAvoid w) -theorem restrictOK_fixConst {S : State n} {w : ℕ} (hw : w ∈ S.params) (b : Bool) : +private theorem restrictOK_fixConst {S : State n} {w : ℕ} (hw : w ∈ S.params) (b : Bool) : S.RestrictOK w (Lit.const b) (S.pairsAvoid w) where mem := hw reads y hy := by simp [Lit.Reads, Lit.const] at hy @@ -547,7 +547,8 @@ theorem Valid.reduction_deleteEqn {S : State n} (hS : S.Valid f) {e v : ℕ} { exact ⟨Finset.mem_erase.2 ⟨hee, hdel.1⟩, Equation.card_subst_le.trans hdel.2⟩ /-- Deleting an equation without terms is a reduction rerouting nothing. -/ -theorem Valid.reduction_dropTrivialEqn {S : State n} (hS : S.Valid f) {e : ℕ} (he : e ∈ S.eqns) +private theorem Valid.reduction_dropTrivialEqn {S : State n} (hS : S.Valid f) {e : ℕ} + (he : e ∈ S.eqns) (hterms : (S.eqn e).terms = ∅) : Reduction f S (S.dropTrivialEqn e) ∅ [.inr e] [] where valid := hS.dropTrivialEqn he hterms subset := Finset.empty_subset _ diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reparameterisation.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reparameterisation.lean index 7217eb281..d1a74b3e8 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reparameterisation.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Reparameterisation.lean @@ -142,7 +142,7 @@ theorem Valid.swap {S : State n} (hS : S.Valid f) {x Q : ℕ} {c : Bool} {T : Fi /-- Along an affine family on which the pair `(x, y)` is tame, the product `(u x + α) (u y + β)` is affine. -/ -theorem isAffine_mul_of_pairTame {k : ℕ} {τ : BitString k → ℕ → Bool} (hτ : IsAffine τ) +private theorem isAffine_mul_of_pairTame {k : ℕ} {τ : BitString k → ℕ → Bool} (hτ : IsAffine τ) {x y : ℕ} (ht : PairTame τ (x, y)) (α β : Bool) : IsAffine fun u => (τ u x + α) * (τ u y + β) := by intro u v w @@ -234,7 +234,7 @@ theorem pair_mem (hS : S.Valid f) : ∀ pr ∈ (S.quad x y z G D α β γ c).pai exact ⟨Finset.mem_insert_of_mem (Finset.mem_erase.2 ⟨hz1, h1⟩), Finset.mem_insert_of_mem (Finset.mem_erase.2 ⟨hz2, h2⟩), h12⟩ -theorem pairs_disjoint (hS : S.Valid f) : ∀ pr ∈ (S.quad x y z G D α β γ c).pairs, +private theorem pairs_disjoint (hS : S.Valid f) : ∀ pr ∈ (S.quad x y z G D α β γ c).pairs, ∀ pr' ∈ (S.quad x y z G D α β γ c).pairs, pr ≠ pr' → pr.1 ≠ pr'.1 ∧ pr.1 ≠ pr'.2 ∧ pr.2 ≠ pr'.1 ∧ pr.2 ≠ pr'.2 := by have hnew : ∀ pr ∈ S.pairs, x ≠ pr.1 ∧ x ≠ pr.2 ∧ y ≠ pr.1 ∧ y ≠ pr.2 := fun pr hpr => @@ -253,7 +253,7 @@ theorem pairs_disjoint (hS : S.Valid f) : ∀ pr ∈ (S.quad x y z G D α β γ /-- Along an affine family on which the new pairs are tame, substituting `z` keeps it affine and every old pair tame: the new pair `(x, y)` makes the product `G` affine. -/ -theorem affine (hS : S.Valid f) {k : ℕ} {τ : BitString k → ℕ → Bool} (hτ : IsAffine τ) +private theorem affine (hS : S.Valid f) {k : ℕ} {τ : BitString k → ℕ → Bool} (hτ : IsAffine τ) (htame : ∀ pr ∈ (S.quad x y z G D α β γ c).pairs, PairTame τ pr) : ∃ τ' : BitString k → ℕ → Bool, IsAffine τ' ∧ (∀ pr ∈ S.pairs, PairTame τ' pr) ∧ ∀ u, ∀ j ∈ S.params, τ' u j = quadValue x y z G D α β γ c (τ u) j := by diff --git a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Step.lean b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Step.lean index 7d9ad27ed..0034e2d19 100644 --- a/Complexity/Computability/Circuit/Boolean/AffineDisperser/Step.lean +++ b/Complexity/Computability/Circuit/Boolean/AffineDisperser/Step.lean @@ -52,7 +52,7 @@ variable {n : ℕ} {f : BooleanFunction n} /-- Lemma 4.2, by induction on the number of gates, the number of auxiliary inputs of the minimal gate and the number of its children reading one of its parameter inputs. -/ -theorem Valid.exists_step_aux {d : ℕ} (hf : IsAffineDisperser f d) : +private theorem Valid.exists_step_aux {d : ℕ} (hf : IsAffineDisperser f d) : ∀ k₁ k₂ k₃ (S : State n), S.gates.card = k₁ → S.auxIn = k₂ → S.childIn = k₃ → S.Valid f → d < S.a → ∃ S', Step f S S' := by intro k₁ diff --git a/Complexity/Computability/Circuit/Boolean/Barrington.lean b/Complexity/Computability/Circuit/Boolean/Barrington.lean index 91ecb80f2..9ee43b2f4 100644 --- a/Complexity/Computability/Circuit/Boolean/Barrington.lean +++ b/Complexity/Computability/Circuit/Boolean/Barrington.lean @@ -246,7 +246,7 @@ def Instruction.entryFormula (I : Instruction (Fin n) Bool (Function.End (Fin w) cases decide (I.select false a = b) <;> cases decide (I.select true a = b) <;> simp /-- The formula of an instruction is a constant or a literal, so in negation normal form. -/ -theorem Instruction.isNNF_entryFormula (I : Instruction (Fin n) Bool (Function.End (Fin w))) +private theorem Instruction.isNNF_entryFormula (I : Instruction (Fin n) Bool (Function.End (Fin w))) (a b : Fin w) : (I.entryFormula a b).IsNNF := by unfold entryFormula cases decide (I.select false a = b) <;> cases decide (I.select true a = b) <;> constructor @@ -287,7 +287,8 @@ def entryFormula (P : MonoidProgram (Fin n) Bool (Function.End (Fin w))) (a b : /-- The formula saying that a branching program maps `a` to `b` has negations only at the leaves. -/ -theorem isNNF_entryFormula (P : MonoidProgram (Fin n) Bool (Function.End (Fin w))) (a b : Fin w) : +private theorem isNNF_entryFormula (P : MonoidProgram (Fin n) Bool (Function.End (Fin w))) + (a b : Fin w) : (P.entryFormula a b).IsNNF := by rw [entryFormula] revert a b diff --git a/Complexity/Computability/Circuit/Boolean/BoundedError.lean b/Complexity/Computability/Circuit/Boolean/BoundedError.lean index 782255b12..5bf4bb72b 100644 --- a/Complexity/Computability/Circuit/Boolean/BoundedError.lean +++ b/Complexity/Computability/Circuit/Boolean/BoundedError.lean @@ -51,7 +51,7 @@ variable {n p : ℕ} /-- If `g` is a threshold of copies of `F` with hardwired random strings, its complexity is at most that of the copies and of the threshold. -/ -theorem complexity_le_of_eq_threshold {m j : ℕ} (F : BooleanFunction (n + p)) +private theorem complexity_le_of_eq_threshold {m j : ℕ} (F : BooleanFunction (n + p)) (g : BooleanFunction n) (ω : Fin m → Fin p → Bool) (h : ∀ x, g x = threshold m j fun i => F (Fin.append x (ω i))) : complexity interpretation (single g) ≤ diff --git a/Complexity/Computability/Circuit/Boolean/CodeComposition.lean b/Complexity/Computability/Circuit/Boolean/CodeComposition.lean index dfebc737c..38449ecca 100644 --- a/Complexity/Computability/Circuit/Boolean/CodeComposition.lean +++ b/Complexity/Computability/Circuit/Boolean/CodeComposition.lean @@ -246,7 +246,7 @@ def appendCodes (n : ℕ) (codes : List (List (Op × List ℕ) × List ℕ)) : @[simp] theorem appendCodes_nil (n : ℕ) : appendCodes n [] = ([], []) := rfl /-- Adding a final block is ordinary shared-input append. -/ -theorem appendCodes_append_singleton (n : ℕ) +private theorem appendCodes_append_singleton (n : ℕ) (codes : List (List (Op × List ℕ) × List ℕ)) (code : List (Op × List ℕ) × List ℕ) : appendCodes n (codes ++ [code]) = appendCode n (appendCodes n codes) code := by simp [appendCodes] @@ -390,7 +390,7 @@ private theorem bundleCode_snoc (n blockSize : ℕ) simp [bundleCode, List.zipIdx_append] /-- Equal-sized blocks occupy exactly their number times their common gate count. -/ -theorem length_bundleCode (n blockSize : ℕ) (codes : List (List (Op × List ℕ) × List ℕ)) +private theorem length_bundleCode (n blockSize : ℕ) (codes : List (List (Op × List ℕ) × List ℕ)) (hlen : ∀ c ∈ codes, c.1.length = blockSize) : (bundleCode n blockSize codes).1.length = codes.length * blockSize := by induction codes using List.reverseRecOn with @@ -403,7 +403,7 @@ theorem length_bundleCode (n blockSize : ℕ) (codes : List (List (Op × List hlen code (by simp)] /-- Adding the next equal-sized block is shared-input append. -/ -theorem bundleCode_append_singleton (n blockSize : ℕ) +private theorem bundleCode_append_singleton (n blockSize : ℕ) (codes : List (List (Op × List ℕ) × List ℕ)) (code : List (Op × List ℕ) × List ℕ) (hlen : ∀ c ∈ codes, c.1.length = blockSize) : bundleCode n blockSize (codes ++ [code]) = diff --git a/Complexity/Computability/Circuit/Boolean/Conondeterministic.lean b/Complexity/Computability/Circuit/Boolean/Conondeterministic.lean index 90c18a87c..d11a9096e 100644 --- a/Complexity/Computability/Circuit/Boolean/Conondeterministic.lean +++ b/Complexity/Computability/Circuit/Boolean/Conondeterministic.lean @@ -49,7 +49,7 @@ noncomputable def econondeterministicAndComplexity (f : BooleanFunction n) : ℕ ecomplexityFrom Monotone.interpretation Monotone.andCost (single g.val) AltFormula.literals /-- A fixed universal verifier bounds the minimum over all verifier functions. -/ -theorem econondeterministicAndComplexity_le_ecomplexityFrom {f : BooleanFunction n} {a : ℕ} +private theorem econondeterministicAndComplexity_le_ecomplexityFrom {f : BooleanFunction n} {a : ℕ} (g : BooleanFunction (n + a)) (hg : forallGuess g = f) : econondeterministicAndComplexity f ≤ ecomplexityFrom Monotone.interpretation Monotone.andCost (single g) AltFormula.literals := by diff --git a/Complexity/Computability/Circuit/Boolean/DepthTime.lean b/Complexity/Computability/Circuit/Boolean/DepthTime.lean index 45a3b8372..5b903f124 100644 --- a/Complexity/Computability/Circuit/Boolean/DepthTime.lean +++ b/Complexity/Computability/Circuit/Boolean/DepthTime.lean @@ -62,7 +62,7 @@ def depthCode (inputCount : ℕ) (code : List (Op × List ℕ) × List ℕ) : simp [wireDepthsCode] /-- The raw table of a typed program lists its zero input depths and then its gate depths. -/ -theorem wireDepthsCode_code (p : Program signature n g) : +private theorem wireDepthsCode_code (p : Program signature n g) : wireDepthsCode n p.code = List.replicate n 0 ++ List.ofFn p.depths := by have h := p.evalCode_code (depthInterpretation 1) 0 (fun _ => 0) rw [← p.depthsWith_one] diff --git a/Complexity/Computability/Circuit/Boolean/DuplicateFlags.lean b/Complexity/Computability/Circuit/Boolean/DuplicateFlags.lean index 98125e0ed..a52ab3cec 100644 --- a/Complexity/Computability/Circuit/Boolean/DuplicateFlags.lean +++ b/Complexity/Computability/Circuit/Boolean/DuplicateFlags.lean @@ -83,7 +83,7 @@ theorem eval_adjacentDuplicateCircuit_iff {input count k : ℕ} tauto /-- Sharing the equality outputs adds exactly one OR gate per record. -/ -theorem cost_program_adjacentDuplicateCircuit {input count k : ℕ} +private theorem cost_program_adjacentDuplicateCircuit {input count k : ℕ} (key : Fin count → Fin k → Fin input) (cost : signature.Op → ℕ) : (adjacentDuplicateCircuit key).program.cost cost = (adjacentEqualityCircuit key).program.cost cost + count * cost .or := by diff --git a/Complexity/Computability/Circuit/Boolean/ElementDistinctness.lean b/Complexity/Computability/Circuit/Boolean/ElementDistinctness.lean index 6ec786815..00fd5e780 100644 --- a/Complexity/Computability/Circuit/Boolean/ElementDistinctness.lean +++ b/Complexity/Computability/Circuit/Boolean/ElementDistinctness.lean @@ -89,7 +89,7 @@ def elementDistinctness (m k : ℕ) : BooleanFunction (m * k) := /-- Element distinctness has at least `2 ^ (t (m - 1))` subfunctions on each block of `2 t` bits when `m ≤ 2 ^ t`. -/ -theorem two_pow_le_card_subfunctions_elementDistinctness (hm : m ≤ 2 ^ t) (i : Fin m) : +private theorem two_pow_le_card_subfunctions_elementDistinctness (hm : m ≤ 2 ^ t) (i : Fin m) : 2 ^ (t * (m - 1)) ≤ #(subfunctions (elementDistinctness m (t + t)) (blockBits (t + t) i)) := by -- Give block `j ≠ i` the value `(j, u j)`. let w (u : {j // j ≠ i} → Fin t → Bool) : Fin m → Fin t → Bool := diff --git a/Complexity/Computability/Circuit/Boolean/Encoding/Certificate.lean b/Complexity/Computability/Circuit/Boolean/Encoding/Certificate.lean index 1b400fccb..f2eaa629a 100644 --- a/Complexity/Computability/Circuit/Boolean/Encoding/Certificate.lean +++ b/Complexity/Computability/Circuit/Boolean/Encoding/Certificate.lean @@ -117,7 +117,7 @@ def readRow (width : ℕ) (row : List Bool) : Op × List ℕ := [((row.drop 3).take width).count true, ((row.drop (3 + width)).take width).count true].take (signature.Arity (Op.ofBits (row.getD 0 false, row.getD 1 false, row.getD 2 false)))) -theorem length_gateRow {width : ℕ} {g : Op × List ℕ} (h : ∀ i ∈ g.2, i ≤ width) : +private theorem length_gateRow {width : ℕ} {g : Op × List ℕ} (h : ∀ i ∈ g.2, i ≤ width) : (gateRow width g).length = 3 + 2 * width := by rw [gateRow, List.length_append, List.length_append, Op.length_bits, length_unaryField _ _ (List.getD_le_of_forall_le h 0), @@ -125,7 +125,8 @@ theorem length_gateRow {width : ℕ} {g : Op × List ℕ} (h : ∀ i ∈ g.2, i omega /-- A row reads as its gate, when the gate has the arity of its operation. -/ -theorem readRow_gateRow {width : ℕ} {g : Op × List ℕ} (harity : g.2.length = signature.Arity g.1) +private theorem readRow_gateRow {width : ℕ} {g : Op × List ℕ} + (harity : g.2.length = signature.Arity g.1) (h : ∀ i ∈ g.2, i ≤ width) : readRow width (gateRow width g) = g := by obtain ⟨op, args⟩ := g have h₀ := length_unaryField _ _ (List.getD_le_of_forall_le h 0) @@ -270,7 +271,7 @@ theorem codeCheck_eq_true_iff {n : ℕ} {gates : List (Op × List ℕ)} : open ComputableTidilyInPolyTime /-- Reading a gate from a row is polynomial-time, for the field width in unary. -/ -theorem computableInPolyTime_readRow : +private theorem computableInPolyTime_readRow : ComputableInPolyTime (fun p : ℕ × List Bool => readRow p.1 p.2) (encPair encUnary encBits) encGate := by refine .of_tidy ?_ diff --git a/Complexity/Computability/Circuit/Boolean/FanInTwo.lean b/Complexity/Computability/Circuit/Boolean/FanInTwo.lean index 1e7d997cf..a911744a0 100644 --- a/Complexity/Computability/Circuit/Boolean/FanInTwo.lean +++ b/Complexity/Computability/Circuit/Boolean/FanInTwo.lean @@ -158,7 +158,7 @@ theorem depth_dedup_le (C : Circuit signature n m) : (dedup C).depth ≤ C.depth Circuit.depth_mapLines_le depth_dedupLine_le C /-- Every gate of `dedup C` reads at most all `n + C.size` wires. -/ -theorem arity_lines_dedup_le (C : Circuit signature n m) (k : Fin C.size) : +private theorem arity_lines_dedup_le (C : Circuit signature n m) (k : Fin C.size) : signature.Arity ((dedup C).program.lines k).op ≤ n + C.size := arity_lines_mapLines_dedupLine_le C.program k diff --git a/Complexity/Computability/Circuit/Boolean/FirstOrder.lean b/Complexity/Computability/Circuit/Boolean/FirstOrder.lean index b083d4ee9..1d8398179 100644 --- a/Complexity/Computability/Circuit/Boolean/FirstOrder.lean +++ b/Complexity/Computability/Circuit/Boolean/FirstOrder.lean @@ -250,7 +250,7 @@ noncomputable def atomsOf (e : M ≃ Fin n) : Atom L n → Bool := fun a => decide (Structure.RelMap a.1.2 (e.symm ∘ a.2)) /-- An enumeration of `M` is an isomorphism onto the structure with the atomic facts of `M`. -/ -def equivModel (e : M ≃ Fin n) : M ≃[L] Model (atomsOf (L := L) e) where +private def equivModel (e : M ≃ Fin n) : M ≃[L] Model (atomsOf (L := L) e) where toEquiv := e map_fun' f := isEmptyElim f map_rel' R t := by @@ -278,7 +278,7 @@ end Structures sentence is decided on the structures with `n` elements, given by their atomic facts, by a formula of negations and unbounded fan-in conjunctions and disjunctions whose depth does not depend on `n` and whose size is polynomial in `n`. -/ -theorem exists_formula_realize (φ : L.Sentence) (e : Atom L n ≃ Fin N) : +private theorem exists_formula_realize (φ : L.Sentence) (e : Atom L n ≃ Fin N) : ∃ F : Formula Unbounded.signature N, (∀ x : Atom L n → Bool, F.eval Unbounded.interpretation (x ∘ e.symm) = true ↔ Model x ⊨ φ) ∧ diff --git a/Complexity/Computability/Circuit/Boolean/Formula/Andreev.lean b/Complexity/Computability/Circuit/Boolean/Formula/Andreev.lean index 8c3441ba1..c389169cc 100644 --- a/Complexity/Computability/Circuit/Boolean/Formula/Andreev.lean +++ b/Complexity/Computability/Circuit/Boolean/Formula/Andreev.lean @@ -138,7 +138,7 @@ def andreevFixTable (b m : ℕ) (h : BooleanFunction b) : andreevFixTable b m h (andreevBlockVar b m j t) = none := by simp [andreevBlockVar] -theorem free_andreevFixTable (b m : ℕ) (h : BooleanFunction b) : +private theorem free_andreevFixTable (b m : ℕ) (h : BooleanFunction b) : (andreevFixTable b m h).free = univ.image (Fin.natAdd (2 ^ b)) := by ext i simp only [PartialAssignment.mem_free, mem_image, mem_univ, true_and] @@ -161,7 +161,7 @@ theorem andreevBlock_subset_free_andreevFixTable (b m : ℕ) (h : BooleanFunctio /-- Under any extension `ρ` of `andreevFixTable b m h`, Andreev's function evaluates `h` on the block parities of `ρ.fill w`. -/ -theorem andreev_fill_of_extends {h : BooleanFunction b} +private theorem andreev_fill_of_extends {h : BooleanFunction b} {ρ : PartialAssignment (Fin (2 ^ b + b * m))} (hext : ρ.Extends (andreevFixTable b m h)) (w : BitString (2 ^ b + b * m)) : andreev b m (ρ.fill w) = @@ -305,7 +305,7 @@ theorem formulaSize_sub_sq_mul_pow_three_le_andreev (h : BooleanFunction b) (hb /-- Specialization of Andreev's reduction to `r = Nat.log 2 b + 2`, for which `2 * b ≤ 2 ^ r` always holds. -/ -theorem formulaSize_sub_sq_mul_pow_three_le_andreev_log (h : BooleanFunction b) (hb : 1 ≤ b) +private theorem formulaSize_sub_sq_mul_pow_three_le_andreev_log (h : BooleanFunction b) (hb : 1 ≤ b) {m : ℕ} (hm : Nat.log 2 b + 2 ≤ m) : (formulaSize h - 2 * b * (Nat.log 2 b + 2)) ^ 2 * m ^ 3 ≤ 4 * formulaSize (andreev b m) ^ 2 * (Nat.log 2 b + 2) ^ 3 := by diff --git a/Complexity/Computability/Circuit/Boolean/Formula/Restriction.lean b/Complexity/Computability/Circuit/Boolean/Formula/Restriction.lean index e25cd962a..ae74be795 100644 --- a/Complexity/Computability/Circuit/Boolean/Formula/Restriction.lean +++ b/Complexity/Computability/Circuit/Boolean/Formula/Restriction.lean @@ -82,13 +82,14 @@ def constValue? : Formula signature n → Option Bool rfl /-- A formula with a constant value is that constant. -/ -theorem eq_const_of_constValue? {F : Formula signature n} {b : Bool} (h : F.constValue? = some b) : +private theorem eq_const_of_constValue? {F : Formula signature n} {b : Bool} + (h : F.constValue? = some b) : F = const b := by match F, h with | gate (.const _) args, rfl => exact congrArg (gate _) (funext fun j => j.elim0) /-- A formula is either a constant or has `constValue? = none`. -/ -theorem eq_const_or_constValue?_eq_none (F : Formula signature n) : +private theorem eq_const_or_constValue?_eq_none (F : Formula signature n) : (∃ b, F = const b) ∨ F.constValue? = none := by cases h : F.constValue? with | none => exact Or.inr rfl @@ -266,11 +267,11 @@ variable (ρ : PartialAssignment (Fin n)) (F.or G).restrict ρ = mkOr (F.restrict ρ) (G.restrict ρ) := rfl -theorem restrict_input_of_eq_none {i : Fin n} (h : ρ i = none) : +private theorem restrict_input_of_eq_none {i : Fin n} (h : ρ i = none) : (input i : Formula signature n).restrict ρ = input i := by simp [h] -theorem restrict_input_of_eq_some {i : Fin n} {b : Bool} (h : ρ i = some b) : +private theorem restrict_input_of_eq_some {i : Fin n} {b : Bool} (h : ρ i = some b) : (input i : Formula signature n).restrict ρ = const b := by simp [h] @@ -351,7 +352,7 @@ theorem IsSimplified.constValue?_eq_none {F : Formula signature n} (hF : F.IsSim cases hF <;> rfl /-- A simplified formula has a leaf. -/ -theorem IsSimplified.one_le_leafSize {F : Formula signature n} (hF : F.IsSimplified) : +private theorem IsSimplified.one_le_leafSize {F : Formula signature n} (hF : F.IsSimplified) : 1 ≤ F.leafSize := by induction hF <;> simp only [leafSize_input, leafSize_not, leafSize_and, leafSize_or] <;> omega diff --git a/Complexity/Computability/Circuit/Boolean/Formula/Subbotovskaya.lean b/Complexity/Computability/Circuit/Boolean/Formula/Subbotovskaya.lean index 8dcd51cf4..113b0dd70 100644 --- a/Complexity/Computability/Circuit/Boolean/Formula/Subbotovskaya.lean +++ b/Complexity/Computability/Circuit/Boolean/Formula/Subbotovskaya.lean @@ -87,7 +87,8 @@ def restrictAt (i : Fin n) (b : Bool) (F : Formula signature n) : Formula signat (F.restrictAt i b).eval interpretation x = F.eval interpretation (update x i b) := by simp [restrictAt] -theorem leafSize_restrictAt_add_leafSizeIn_le (F : Formula signature n) (i : Fin n) (b : Bool) : +private theorem leafSize_restrictAt_add_leafSizeIn_le (F : Formula signature n) (i : Fin n) + (b : Bool) : (F.restrictAt i b).leafSize + F.leafSizeIn {i} ≤ F.leafSize := leafSize_restrict_update_le F i b @@ -111,7 +112,7 @@ theorem restrictAt_input_self (i : Fin n) (b : Bool) : (input i : Formula signature n).restrictAt i b = const b := by simp [restrictAt] -theorem restrictAt_input_of_ne {i j : Fin n} (h : j ≠ i) (b : Bool) : +private theorem restrictAt_input_of_ne {i j : Fin n} (h : j ≠ i) (b : Bool) : (input j : Formula signature n).restrictAt i b = input j := by simp [restrictAt, h] @@ -131,7 +132,7 @@ theorem isLeafMinimal_iff_leafSize_eq_formulaSize {F : Formula signature n} : fun h _ hG => h ▸ formulaSize_le hG⟩ /-- Every argument of a leaf-minimal gate is leaf-minimal. -/ -theorem IsLeafMinimal.arg {op : Op} {args : Fin (signature.Arity op) → Formula signature n} +private theorem IsLeafMinimal.arg {op : Op} {args : Fin (signature.Arity op) → Formula signature n} (hF : (gate op args).IsLeafMinimal) (j : Fin (signature.Arity op)) : (args j).IsLeafMinimal := by intro G hG @@ -154,23 +155,25 @@ theorem IsLeafMinimal.arg {op : Op} {args : Fin (signature.Arity op) → Formula rw [← hsum1, ← hsum2, update_self, heq] at hle omega -theorem IsLeafMinimal.of_not {F : Formula signature n} (h : F.not.IsLeafMinimal) : +private theorem IsLeafMinimal.of_not {F : Formula signature n} (h : F.not.IsLeafMinimal) : F.IsLeafMinimal := h.arg 0 -theorem IsLeafMinimal.left_of_and {F G : Formula signature n} (h : (F.and G).IsLeafMinimal) : +private theorem IsLeafMinimal.left_of_and {F G : Formula signature n} + (h : (F.and G).IsLeafMinimal) : F.IsLeafMinimal := h.arg 0 -theorem IsLeafMinimal.right_of_and {F G : Formula signature n} (h : (F.and G).IsLeafMinimal) : +private theorem IsLeafMinimal.right_of_and {F G : Formula signature n} + (h : (F.and G).IsLeafMinimal) : G.IsLeafMinimal := h.arg 1 -theorem IsLeafMinimal.left_of_or {F G : Formula signature n} (h : (F.or G).IsLeafMinimal) : +private theorem IsLeafMinimal.left_of_or {F G : Formula signature n} (h : (F.or G).IsLeafMinimal) : F.IsLeafMinimal := h.arg 0 -theorem IsLeafMinimal.right_of_or {F G : Formula signature n} (h : (F.or G).IsLeafMinimal) : +private theorem IsLeafMinimal.right_of_or {F G : Formula signature n} (h : (F.or G).IsLeafMinimal) : G.IsLeafMinimal := h.arg 1 @@ -434,7 +437,7 @@ theorem sum_formulaSize_restrict_update_le (f : BooleanFunction n) /-- Uniform single-step shrinkage inequality valid for every formula size, including `1`: the sum over all `2 |ρ.free|` single-variable extensions of `ρ` is at most `(2 |ρ.free| - 3) L(f↾ρ) + 1`. -/ -theorem sum_formulaSize_restrict_update_le_add_one (f : BooleanFunction n) +private theorem sum_formulaSize_restrict_update_le_add_one (f : BooleanFunction n) (ρ : PartialAssignment (Fin n)) : ∑ i ∈ ρ.free, (formulaSize (f ∘ PartialAssignment.fill (update ρ i (some false))) + diff --git a/Complexity/Computability/Circuit/Boolean/GateElimination.lean b/Complexity/Computability/Circuit/Boolean/GateElimination.lean index d67ab1c19..b640a272e 100644 --- a/Complexity/Computability/Circuit/Boolean/GateElimination.lean +++ b/Complexity/Computability/Circuit/Boolean/GateElimination.lean @@ -94,29 +94,30 @@ def IsConstOrLiteral (φ : BooleanFunction n) : Prop := obtain ⟨d, h₂⟩ := h₂ exact ⟨d ^^ c, fun x => by rw [h₁ x, h₂ x, Bool.xor_assoc]⟩ -theorem EqUpToNeg.isConst (h : EqUpToNeg φ ψ) (hψ : IsConst ψ) : IsConst φ := by +private theorem EqUpToNeg.isConst (h : EqUpToNeg φ ψ) (hψ : IsConst ψ) : IsConst φ := by obtain ⟨c, h⟩ := h exact fun x y => by rw [h, h, hψ x y] -theorem EqUpToNeg.isConstOrLiteral (h : EqUpToNeg φ ψ) (hψ : IsConstOrLiteral ψ) : +private theorem EqUpToNeg.isConstOrLiteral (h : EqUpToNeg φ ψ) (hψ : IsConstOrLiteral ψ) : IsConstOrLiteral φ := hψ.imp h.isConst fun ⟨i, hi⟩ => ⟨i, h.trans hi⟩ -theorem EqUpToNeg.dependsOn {s : Set (Fin n)} (h : EqUpToNeg φ ψ) (hψ : DependsOn ψ s) : +private theorem EqUpToNeg.dependsOn {s : Set (Fin n)} (h : EqUpToNeg φ ψ) (hψ : DependsOn ψ s) : DependsOn φ s := by obtain ⟨c, h⟩ := h exact fun x y hxy => by rw [h, h, hψ hxy] -theorem EqUpToNeg.comp_right (h : EqUpToNeg φ ψ) (f : BitString n → BitString n) : +private theorem EqUpToNeg.comp_right (h : EqUpToNeg φ ψ) (f : BitString n → BitString n) : EqUpToNeg (φ ∘ f) (ψ ∘ f) := by obtain ⟨c, h⟩ := h exact ⟨c, fun x => h _⟩ -theorem isConstOrLiteral_literal (i : Fin n) : IsConstOrLiteral fun x : BitString n => x i := +private theorem isConstOrLiteral_literal (i : Fin n) : + IsConstOrLiteral fun x : BitString n => x i := Or.inr ⟨i, EqUpToNeg.refl _⟩ /-- A function of bit `i` alone is constant or a literal. -/ -theorem isConstOrLiteral_of_eq_comp (f : Bool → Bool) (h : ∀ x, φ x = f (x i)) : +private theorem isConstOrLiteral_of_eq_comp (f : Bool → Bool) (h : ∀ x, φ x = f (x i)) : IsConstOrLiteral φ := by cases h0 : f false <;> cases h1 : f true · exact Or.inl fun x y => by rw [h, h]; cases x i <;> cases y i <;> simp [h0, h1] @@ -125,7 +126,8 @@ theorem isConstOrLiteral_of_eq_comp (f : Bool → Bool) (h : ∀ x, φ x = f (x · exact Or.inl fun x y => by rw [h, h]; cases x i <;> cases y i <;> simp [h0, h1] /-- Hardwiring bits keeps constants and literals. -/ -theorem IsConstOrLiteral.comp_fill (h : IsConstOrLiteral φ) (ρ : PartialAssignment (Fin n)) : +private theorem IsConstOrLiteral.comp_fill (h : IsConstOrLiteral φ) + (ρ : PartialAssignment (Fin n)) : IsConstOrLiteral (φ ∘ ρ.fill) := by rcases h with h | ⟨i, c, h⟩ · exact Or.inl fun x y => h _ _ @@ -134,7 +136,7 @@ theorem IsConstOrLiteral.comp_fill (h : IsConstOrLiteral φ) (ρ : PartialAssign | some b => exact Or.inl fun x y => by simp [h, hi] /-- A constant or a literal is bit `i` up to negation or ignores it. -/ -theorem IsConstOrLiteral.eqUpToNeg_or_dependsOn (h : IsConstOrLiteral φ) (i : Fin n) : +private theorem IsConstOrLiteral.eqUpToNeg_or_dependsOn (h : IsConstOrLiteral φ) (i : Fin n) : EqUpToNeg φ (· i) ∨ DependsOn φ {i}ᶜ := by rcases h with h | ⟨u, hu⟩ · exact Or.inr fun x y _ => h x y @@ -260,25 +262,25 @@ private theorem restricted_gate (ρ : PartialAssignment (Fin n)) (k : Fin g) : restricted p ρ (.gate k) = lineFunction (p.lines k) (restricted p ρ) := funext (restricted_gate_apply p ρ k) -theorem isConstOrLiteral_restricted_input (ρ : PartialAssignment (Fin n)) (i : Fin n) : +private theorem isConstOrLiteral_restricted_input (ρ : PartialAssignment (Fin n)) (i : Fin n) : IsConstOrLiteral (restricted p ρ (.input i)) := (isConstOrLiteral_literal i).comp_fill ρ variable {p} {ρ : PartialAssignment (Fin n)} {i : Fin n} /-- Fixing one more free bit is restricting the restricted function. -/ -theorem restricted_update (hi : ρ i = none) (b : Bool) (w : Wire n g) : +private theorem restricted_update (hi : ρ i = none) (b : Bool) (w : Wire n g) : restricted p (update ρ i (some b)) w = restricted p ρ w ∘ PartialAssignment.fill (update ρ i (some b)) := by funext x simp only [restricted, comp_apply, PartialAssignment.fill_fill_update hi] -theorem restricted_update_of_ne_none (hi : ρ i ≠ none) (w : Wire n g) (x : BitString n) +private theorem restricted_update_of_ne_none (hi : ρ i ≠ none) (w : Wire n g) (x : BitString n) (c : Bool) : restricted p ρ w (update x i c) = restricted p ρ w x := by simp only [restricted, comp_apply, PartialAssignment.fill_update_of_ne_none hi] /-- A wire that is another up to negation is constant when the other is, after fixing a bit. -/ -theorem isConst_update_of_eqUpToNeg (hi : ρ i = none) (a : Bool) {w w' : Wire n g} +private theorem isConst_update_of_eqUpToNeg (hi : ρ i = none) (a : Bool) {w w' : Wire n g} (h : EqUpToNeg (restricted p ρ w) (restricted p ρ w')) (hc : IsConst (restricted p (update ρ i (some a)) w')) : IsConst (restricted p (update ρ i (some a)) w) := by @@ -287,7 +289,7 @@ theorem isConst_update_of_eqUpToNeg (hi : ρ i = none) (a : Bool) {w w' : Wire n /-- Fixing a free bit of the parity of all free bits leaves the parity of the others, possibly negated. -/ -theorem restricted_update_of_parity {o : Wire n g} (hi : ρ i = none) (b : Bool) {c : Bool} +private theorem restricted_update_of_parity {o : Wire n g} (hi : ρ i = none) (b : Bool) {c : Bool} (ho : ∀ x, restricted p ρ o x = (c ^^ parityOn ρ.free x)) (x : BitString n) : restricted p (update ρ i (some b)) o x = ((c ^^ b) ^^ parityOn (PartialAssignment.free (update ρ i (some b))) x) := by @@ -327,7 +329,7 @@ variable {p} {ρ : PartialAssignment (Fin n)} {i : Fin n} variable (p ρ) in /-- There are at most as many nonredundant gates as binary gates. -/ -theorem card_nonRedundant_le : #(nonRedundant p ρ) ≤ p.cost binaryCost := by +private theorem card_nonRedundant_le : #(nonRedundant p ρ) ≤ p.cost binaryCost := by rw [Program.cost_eq_sum] simp only [binaryCost_eq_ite, ← card_filter] exact card_le_card fun k hk => mem_filter.2 ⟨mem_univ _, (mem_nonRedundant.1 hk).1⟩ @@ -467,7 +469,7 @@ section Step variable {p : Program signature n g} {ρ : PartialAssignment (Fin n)} {o : Wire n g} -theorem not_isConstOrLiteral_parityOn {s : Finset (Fin n)} (hs : 2 ≤ #s) (c : Bool) : +private theorem not_isConstOrLiteral_parityOn {s : Finset (Fin n)} (hs : 2 ≤ #s) (c : Bool) : ¬IsConstOrLiteral fun x => c ^^ parityOn s x := by rintro (h | ⟨u, hu⟩) · exact not_isConst_parityOn (card_pos.1 (by omega)) c h @@ -531,7 +533,7 @@ variable (p o) in /-- **Schnorr's elimination step.** If, under `ρ`, the wire `o` computes the parity of all free bits, possibly negated, and at least two bits are free, then fixing one free bit suitably makes at least three nonredundant gates redundant. -/ -theorem exists_card_add_three_le {c : Bool} +private theorem exists_card_add_three_le {c : Bool} (ho : ∀ x, restricted p ρ o x = (c ^^ parityOn ρ.free x)) (hV : 2 ≤ #ρ.free) : ∃ i b, ρ i = none ∧ #(nonRedundant p (update ρ i (some b))) + 3 ≤ #(nonRedundant p ρ) := by @@ -612,7 +614,7 @@ theorem exists_card_add_three_le {c : Bool} variable (p o) in /-- Under a restriction leaving `m + 1` bits free for which the wire `o` computes their parity, possibly negated, at least `3 m` gates are nonredundant. -/ -theorem three_mul_le_card_nonRedundant (m : ℕ) (ρ : PartialAssignment (Fin n)) (c : Bool) +private theorem three_mul_le_card_nonRedundant (m : ℕ) (ρ : PartialAssignment (Fin n)) (c : Bool) (hρ : #ρ.free = m + 1) (ho : ∀ x, restricted p ρ o x = (c ^^ parityOn ρ.free x)) : 3 * m ≤ #(nonRedundant p ρ) := by induction m generalizing ρ c with diff --git a/Complexity/Computability/Circuit/Boolean/Hastad.lean b/Complexity/Computability/Circuit/Boolean/Hastad.lean index d6fede79a..fde1cef33 100644 --- a/Complexity/Computability/Circuit/Boolean/Hastad.lean +++ b/Complexity/Computability/Circuit/Boolean/Hastad.lean @@ -184,7 +184,7 @@ theorem exists_dnf_of_shallow {op : Op} (hop : op ≠ .not) {args : Fin op.arity disjunction have decision tree depth at most `k` under `ρ`, at most `#E(ℓ - s) (4k)^s` of the extensions of `ρ` with `ℓ` free bits leave it `s`-deep, where `E(m)` are the extensions of `ρ` with `m` free bits. -/ -theorem card_filter_not_shallow_le_of_ne_not {op : Op} (hop : op ≠ .not) {k : ℕ} +private theorem card_filter_not_shallow_le_of_ne_not {op : Op} (hop : op ≠ .not) {k : ℕ} {args : Fin op.arity → BitString n → Bool} (h : ∀ j, Shallow (k + 1) ρ (args j)) (ℓ s : ℕ) : #{ρ' ∈ ρ.extensions ℓ | ¬ Shallow s ρ' fun x => interpretation op fun j => args j x} ≤ #(ρ.extensions (ℓ - s)) * (4 * k) ^ s := by @@ -203,7 +203,7 @@ theorem card_filter_not_shallow_le_of_ne_not {op : Op} (hop : op ≠ .not) {k : /-- **The switching step for one operation.** If the arguments of an operation are shallow under `ρ`, few extensions of `ρ` leave it deep. -/ -theorem card_filter_not_shallow_le {op : Op} {args : Fin op.arity → BitString n → Bool} +private theorem card_filter_not_shallow_le {op : Op} {args : Fin op.arity → BitString n → Bool} (h : ∀ j, Shallow s ρ (args j)) (ℓ : ℕ) : #{ρ' ∈ ρ.extensions ℓ | ¬ Shallow s ρ' fun x => interpretation op fun j => args j x} ≤ #(ρ.extensions (ℓ - s)) * (4 * s) ^ s := by @@ -263,7 +263,7 @@ variable {g : ℕ} /-- If every gate of depth at most `j` is shallow under `ρ`, so is every argument of a gate of depth at most `j + 1`. -/ -theorem shallow_trace_wires {p : Program signature n g} (hs : 2 ≤ s) {j : ℕ} +private theorem shallow_trace_wires {p : Program signature n g} (hs : 2 ≤ s) {j : ℕ} (hρ : ∀ k, p.depths k ≤ j → Shallow s ρ fun x => p.eval interpretation x k) {k : Fin g} (hk : p.depths k ≤ j + 1) (a : Fin (p.lines k).op.arity) : Shallow s ρ fun x => p.trace interpretation x ((p.lines k).wires a) := by diff --git a/Complexity/Computability/Circuit/Boolean/Hastad/Sharp.lean b/Complexity/Computability/Circuit/Boolean/Hastad/Sharp.lean index 6b96bef18..a81b914c7 100644 --- a/Complexity/Computability/Circuit/Boolean/Hastad/Sharp.lean +++ b/Complexity/Computability/Circuit/Boolean/Hastad/Sharp.lean @@ -297,7 +297,7 @@ private theorem not_forall_trace_fill_eq_parity_bne {p : Program signature n g} /-- **Håstad's theorem with the sharp exponent**, for programs: if a wire of AND/OR depth at most `d` computes the parity of `n` bits, the program has at least `2 ^ s` conjunctions and disjunctions, for every `s ≥ 2` with `17 s (16 s + 1) ^ (d - 2) ≤ n`. -/ -theorem two_pow_le_card_andOr_of_trace_eq_parity {p : Program signature n g} {w : Wire n g} +private theorem two_pow_le_card_andOr_of_trace_eq_parity {p : Program signature n g} {w : Wire n g} (hw : ∀ x, p.trace interpretation x w = parity n x) (hs : 2 ≤ s) {d : ℕ} (hd : p.wireDepthsWith andOrCost w ≤ d) (hn : 17 * s * (16 * s + 1) ^ (d - 2) ≤ n) : 2 ^ s ≤ #{k | (p.lines k).op ≠ .not} := by diff --git a/Complexity/Computability/Circuit/Boolean/Hierarchy.lean b/Complexity/Computability/Circuit/Boolean/Hierarchy.lean index 2637da7ad..ec4e632e2 100644 --- a/Complexity/Computability/Circuit/Boolean/Hierarchy.lean +++ b/Complexity/Computability/Circuit/Boolean/Hierarchy.lean @@ -133,7 +133,7 @@ theorem complexity_const (b : Bool) : /-- **Discrete intermediate values.** If changing one coordinate raises a measure by at most `B`, and the measure is at most `t` at `u` and above `t` at `v`, then it lies in `(t, t + B]` somewhere. -/ -theorem exists_lt_le_add_of_update_le {ι α : Type*} [Finite ι] [DecidableEq ι] +private theorem exists_lt_le_add_of_update_le {ι α : Type*} [Finite ι] [DecidableEq ι] (μ : (ι → α) → ℕ) {B t : ℕ} (hμ : ∀ w i a, μ (Function.update w i a) ≤ μ w + B) {u v : ι → α} (hu : μ u ≤ t) (hv : t < μ v) : ∃ w, t < μ w ∧ μ w ≤ t + B := by have := Fintype.ofFinite ι diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Active.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Active.lean index 0b1e9ee14..f7d51b5b0 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Active.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Active.lean @@ -46,7 +46,7 @@ namespace Cslib.Circuits.Boolean.Iteration open FunctionalGraph -theorem active_construction_cost (n s M L d : ℕ) (hL : 0 < L) (hd : d ≤ n + 3) +private theorem active_construction_cost (n s M L d : ℕ) (hL : 0 < L) (hd : d ≤ n + 3) (hR : 2 ^ d ≤ 2 * (M + 4 * L + 1)) : 2 + 5 * (4 * L) * s + (18 * d ^ 2 + 30) * 2 ^ d * (Record.width n (n + 3) + 1) + 1000 * (4 * L + 1) * (n + (n + 3) + 1) ^ 2 ≤ diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Batch.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Batch.lean index d660683ed..ba6144e4f 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Batch.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Batch.lean @@ -77,7 +77,7 @@ theorem batchBudget_one (n s M L : ℕ) : batchBudget n s M 1 L = powerBudget n simp only [batchBudget, powerBudget, Nat.one_mul] /-- A synthesis of every member's output block gives a circuit for the block map. -/ -theorem exists_circuit_blockMap {k : ℕ} {g : BitString n → BitString k} {C : ℕ} +private theorem exists_circuit_blockMap {k : ℕ} {g : BitString n → BitString k} {C : ℕ} (h : Synthesis interpretation (inputs (r * n)) (⋃ member, wires fun x => g (directProductInput x member)) C) : ∃ out : Circuit signature (r * n) (r * k), @@ -182,7 +182,7 @@ theorem synthesis_batched_power (c : Circuit signature n n) (s : Set (BooleanFun omega /-- The construction cost is within `100000` times the batched tradeoff. -/ -theorem batch_construction_cost (n s M r L : ℕ) (hrN : r ≤ 2 ^ n) (hL : 0 < L) +private theorem batch_construction_cost (n s M r L : ℕ) (hrN : r ≤ 2 ^ n) (hL : 0 < L) (hLN : L ≤ 2 ^ n) (hM : M ≤ 2 ^ n / L) : 2 + (r * (2 * L * s) + 48 * (r * (2 * L + 1) + M + 1) * (Nat.clog 2 (r * (2 * L + 1) + M) + 1) ^ 2 * @@ -301,7 +301,7 @@ theorem optimizedBatchBudget_one (n s M : ℕ) : optimizedBatchBudget n s M 1 = optimizedBudget n s M := by simp only [optimizedBatchBudget, optimizedBudget, Nat.one_mul] -theorem exists_batchBudget_le_optimizedBatchBudget (n s M r : ℕ) (hr : 0 < r) +private theorem exists_batchBudget_le_optimizedBatchBudget (n s M r : ℕ) (hr : 0 < r) (hM : M ≤ 2 ^ n) : ∃ L : ℕ, 0 < L ∧ L ≤ 2 ^ n ∧ (batchBudget n s M r L : ℝ) ≤ 3 * optimizedBatchBudget n s M r := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/CounterBatch.lean b/Complexity/Computability/Circuit/Boolean/Iteration/CounterBatch.lean index 71065a415..0774c3d78 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/CounterBatch.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/CounterBatch.lean @@ -158,16 +158,16 @@ theorem iterate_counterBatchPower (T : ℕ) : ModulusCounter.power_add] /-- The left half (the modulus) of every state is preserved by `ModulusCounter.power T`. -/ -theorem counterStep_iterate_left (T : ℕ) (y : BitString (k + k)) (i : Fin k) : +private theorem counterStep_iterate_left (T : ℕ) (y : BitString (k + k)) (i : Fin k) : ModulusCounter.power T y (Fin.castAdd k i) = y (Fin.castAdd k i) := by simp [ModulusCounter.power, ModulusCounter.pack, ModulusCounter.leftWord] /-- States with modulus zero are fixed by `ModulusCounter.power T`. -/ -theorem counterStep_iterate_joinState_zero (T : ℕ) (b : BitVec k) : +private theorem counterStep_iterate_joinState_zero (T : ℕ) (b : BitVec k) : ModulusCounter.power T (ModulusCounter.pack 0 b) = ModulusCounter.pack 0 b := by simp [ModulusCounter.power, ModulusCounter.advance] -theorem joinState_zero_zero : ModulusCounter.pack (0 : BitVec k) 0 = fun _ => false := by +private theorem joinState_zero_zero : ModulusCounter.pack (0 : BitVec k) 0 = fun _ => false := by funext bit induction bit using Fin.addCases <;> simp only [ModulusCounter.pack, Fin.append_left, Fin.append_right] <;> @@ -191,7 +191,8 @@ theorem residueKeys_injective (k : ℕ) : Function.Injective (residueKeys k) := simp only [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hi, Nat.mod_eq_of_lt hj] at hn exact Fin.ext (by omega) -theorem clog_two_pow_add_le (hr : r ≤ 2 ^ (k + k)) : Nat.clog 2 (r + (2 ^ k - 1)) ≤ 2 * k + 1 := by +private theorem clog_two_pow_add_le (hr : r ≤ 2 ^ (k + k)) : + Nat.clog 2 (r + (2 ^ k - 1)) ≤ 2 * k + 1 := by apply Nat.clog_le_of_le_pow have h1 : 2 ^ k ≤ 2 ^ (k + k) := Nat.pow_le_pow_right (by decide) (by omega) rw [show 2 * k + 1 = (k + k) + 1 by omega, pow_succ] diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Basic.lean b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Basic.lean index 1be0efb13..322cfbd95 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Basic.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Basic.lean @@ -97,18 +97,18 @@ theorem length_le_period (hf : Function.Injective f) (j : Fin R) : end CounterIntervalChart /-- Starts of the linear pieces; the last counter edge creates no additional piece. -/ -noncomputable def counterIntervalStarts (f : BitVec n → BitVec n) : Finset ℕ := +private noncomputable def counterIntervalStarts (f : BitVec n → BitVec n) : Finset ℕ := insert 0 (((disagreement f (fun x => x + 1)).image (fun x => x.toNat + 1)).filter fun a => a < 2 ^ n) -theorem counterIntervalStarts_bound (f : BitVec n → BitVec n) : +private theorem counterIntervalStarts_bound (f : BitVec n → BitVec n) : (counterIntervalStarts f).card ≤ (disagreement f (fun x => x + 1)).card + 1 := by classical unfold counterIntervalStarts exact (Finset.card_insert_le _ _).trans (Nat.add_le_add_right ((Finset.card_filter_le _ _).trans (Finset.card_image_le)) 1) -theorem counterIntervalStarts_lt (f : BitVec n → BitVec n) {a : ℕ} +private theorem counterIntervalStarts_lt (f : BitVec n → BitVec n) {a : ℕ} (ha : a ∈ counterIntervalStarts f) : a < 2 ^ n := by classical rcases Finset.mem_insert.mp ha with rfl | ha @@ -119,7 +119,7 @@ theorem counterIntervalStarts_lt (f : BitVec n → BitVec n) {a : ℕ} def nextBoundary (S : Finset ℕ) (N a : ℕ) : ℕ := (insert N (S.filter fun b => a < b)).min' (by simp) -theorem nextBoundary_gt (S : Finset ℕ) {N a : ℕ} (ha : a < N) : +private theorem nextBoundary_gt (S : Finset ℕ) {N a : ℕ} (ha : a < N) : a < nextBoundary S N a := by have h := Finset.min'_mem (insert N (S.filter fun b => a < b)) (by simp) rcases Finset.mem_insert.mp h with he | he @@ -127,7 +127,7 @@ theorem nextBoundary_gt (S : Finset ℕ) {N a : ℕ} (ha : a < N) : exact he.symm ▸ ha · exact (Finset.mem_filter.mp he).2 -theorem nextBoundary_le (S : Finset ℕ) (N a : ℕ) : nextBoundary S N a ≤ N := +private theorem nextBoundary_le (S : Finset ℕ) (N a : ℕ) : nextBoundary S N a ≤ N := Finset.min'_le _ _ (by simp) theorem nextBoundary_le_of_mem (S : Finset ℕ) (N a b : ℕ) @@ -135,7 +135,7 @@ theorem nextBoundary_le_of_mem (S : Finset ℕ) (N a b : ℕ) Finset.min'_le _ _ (by simp [hb, hab]) /-- A finite set of starts containing zero covers the whole linear universe. -/ -theorem exists_covering_interval (S : Finset ℕ) {N x : ℕ} +private theorem exists_covering_interval (S : Finset ℕ) {N x : ℕ} (hzero : 0 ∈ S) (hx : x < N) : ∃ a ∈ S, a ≤ x ∧ x < nextBoundary S N a := by let before := S.filter fun a => a ≤ x @@ -157,7 +157,7 @@ theorem exists_covering_interval (S : Finset ℕ) {N x : ℕ} lia /-- Before the next cut, the actual update agrees with numerical increment. -/ -theorem counterInterval_step (f : BitVec n → BitVec n) {a i : ℕ} +private theorem counterInterval_step (f : BitVec n → BitVec n) {a i : ℕ} (hai : a ≤ i) (hi : i + 1 < nextBoundary (counterIntervalStarts f) (2 ^ n) a) : f (BitVec.ofNat n i) = BitVec.ofNat n (i + 1) := by classical diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Decode.lean b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Decode.lean index 9ca6004d8..bd499b142 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Decode.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Decode.lean @@ -51,7 +51,7 @@ noncomputable def negativePhase (j : Fin R) : BitVec (chartWidth n) := noncomputable def phaseDistance (j : Fin R) (p : BitVec (chartWidth n)) : BitVec (chartWidth n) := addResidue (chart.period j) p (chart.negativePhase j) -theorem phaseDistance_toNat (j : Fin R) (p : BitVec (chartWidth n)) +private theorem phaseDistance_toNat (j : Fin R) (p : BitVec (chartWidth n)) (hp : p.toNat < cycleLength f (chart.first j)) : (chart.phaseDistance j p).toNat = (p.toNat + cycleLength f (chart.first j) - @@ -69,7 +69,7 @@ theorem phaseDistance_toNat (j : Fin R) (p : BitVec (chartWidth n)) (cycleLength f (chart.first j) - phase f (chart.first j)) (cycleLength_pos f _) /-- The decoded distance is exactly the numerical offset within a containing interval. -/ -theorem phaseDistance_of_contains (hf : Function.Injective f) (j : Fin R) (y : BitVec n) +private theorem phaseDistance_of_contains (hf : Function.Injective f) (j : Fin R) (y : BitVec n) (hy : chart.contains j y = true) : (chart.phaseDistance j (BitVec.ofNat (chartWidth n) (phase f y))).toNat = y.toNat - chart.start j := by @@ -89,7 +89,7 @@ theorem phaseDistance_of_contains (hf : Function.Injective f) (j : Fin R) (y : B simp only [Nat.ModEq, hphase, Nat.add_comm, Nat.mod_mod] /-- On a matching cycle, the decoded distance really reaches the requested state. -/ -theorem phaseDistance_hit (hf : Function.Injective f) (j : Fin R) (y : BitVec n) +private theorem phaseDistance_hit (hf : Function.Injective f) (j : Fin R) (y : BitVec n) (hc : canonicalCycle f (chart.first j) = canonicalCycle f y) : f^[(chart.phaseDistance j (BitVec.ofNat (chartWidth n) (phase f y))).toNat] (chart.first j) = y := by @@ -111,7 +111,7 @@ theorem phaseDistance_hit (hf : Function.Injective f) (j : Fin R) (y : BitVec n) noncomputable def decodedRow (j : Fin R) (p : BitVec (chartWidth n)) : BitVec n := BitVec.ofNat n (chart.start j) + (chart.phaseDistance j p).setWidth n -theorem decodedRow_eq (j : Fin R) (p : BitVec (chartWidth n)) : +private theorem decodedRow_eq (j : Fin R) (p : BitVec (chartWidth n)) : chart.decodedRow j p = BitVec.ofNat n (chart.start j + (chart.phaseDistance j p).toNat) := by simp only [decodedRow, BitVec.ofNat_add, BitVec.ofNat_toNat] @@ -119,7 +119,7 @@ theorem decodedRow_eq (j : Fin R) (p : BitVec (chartWidth n)) : noncomputable def decodeFlag (j : Fin R) (rep : BitVec n) (p : BitVec (chartWidth n)) : Bool := decide (rep = canonicalCycle f (chart.first j)) && (chart.phaseDistance j p).ult (chart.length j) -theorem decodeFlag_of_contains (hf : Function.Injective f) (j : Fin R) (y : BitVec n) +private theorem decodeFlag_of_contains (hf : Function.Injective f) (j : Fin R) (y : BitVec n) (hy : chart.contains j y = true) : chart.decodeFlag j (canonicalCycle f y) (BitVec.ofNat (chartWidth n) (phase f y)) = true := by obtain ⟨hlo, hhi⟩ := (chart.contains_iff j y).mp hy @@ -129,7 +129,7 @@ theorem decodeFlag_of_contains (hf : Function.Injective f) (j : Fin R) (y : BitV chart.phaseDistance_of_contains hf j y hy, length_toNat] lia -theorem decodedRow_spec (hf : Function.Injective f) (j : Fin R) (y : BitVec n) +private theorem decodedRow_spec (hf : Function.Injective f) (j : Fin R) (y : BitVec n) (hy : chart.decodeFlag j (canonicalCycle f y) (BitVec.ofNat (chartWidth n) (phase f y)) = true) : chart.decodedRow j (BitVec.ofNat (chartWidth n) (phase f y)) = y := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Encode.lean b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Encode.lean index e127ac2d4..e9387da9f 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Encode.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/CounterChart/Encode.lean @@ -66,7 +66,7 @@ theorem chart_ofNat_toNat {a : ℕ} (ha : a ≤ 2 ^ n) : have := Nat.two_pow_pos n lia -theorem chart_setWidth_toNat (x : BitVec n) : +private theorem chart_setWidth_toNat (x : BitVec n) : (x.setWidth (chartWidth n)).toNat = x.toNat := by simpa only [BitVec.ofNat_toNat] using chart_ofNat_toNat x.isLt.le @@ -124,7 +124,7 @@ def contains (j : Fin R) (x : BitVec n) : Bool := def offset (j : Fin R) (x : BitVec n) : BitVec (chartWidth n) := x.setWidth (chartWidth n) - BitVec.ofNat (chartWidth n) (chart.start j) -theorem offset_toNat (j : Fin R) (x : BitVec n) (hx : chart.start j ≤ x.toNat) : +private theorem offset_toNat (j : Fin R) (x : BitVec n) (hx : chart.start j ≤ x.toNat) : (chart.offset j x).toNat = x.toNat - chart.start j := by have hw := chart_setWidth_toNat x have hs := chart_ofNat_toNat (chart.start_lt j).le @@ -137,7 +137,7 @@ noncomputable def encodedRow (j : Fin R) (x : BitVec n) : labelBits (fun i => (canonicalCycle f (chart.first j)).getLsbD i.val) (chart.period j) (addResidue (chart.period j) (chart.initialPhase j) (chart.offset j x)) -theorem encodedRow_spec (hf : Function.Injective f) (j : Fin R) (x : BitVec n) +private theorem encodedRow_spec (hf : Function.Injective f) (j : Fin R) (x : BitVec n) (hx : chart.contains j x = true) : chart.encodedRow j x = wordCycleLabel f x := by obtain ⟨hlo, hhi⟩ := (chart.contains_iff j x).mp hx have hpath := chart.point_eq j x hlo hhi diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Decoder.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Decoder.lean index 3b21f2fef..1ef6e96c9 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Decoder.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Decoder.lean @@ -77,7 +77,7 @@ theorem hitValue_spec (f : BitString n → BitString n) (T K d : ℕ) (x : BitSt congr 1 omega -theorem repeatedValue_spec (f : BitString n → BitString n) (T K i j : ℕ) (x : BitString n) +private theorem repeatedValue_spec (f : BitString n → BitString n) (T K i j : ℕ) (x : BitString n) (hij : i < j) (hj : j ≤ K) (hK : K < 2 ^ w) (hT : K ≤ T) (heq : f^[i] x = f^[j] x) : repeatedValue f T K x (BitVec.ofNat w i) (BitVec.ofNat w j) = f^[T] x := by have hiw : (BitVec.ofNat w i).toNat = i := Nat.mod_eq_of_lt (by omega) @@ -118,7 +118,8 @@ theorem prefix_mem (f : BitString n → BitString n) {K j : ℕ} (hj : j ≤ K) (fun x => f^[j] x bit) ∈ prefixWires f K := Synthesis.subset_stages _ hj ⟨bit, rfl⟩ -theorem synthesis_repeatedValue (s : Set (BooleanFunction n)) (f : BitString n → BitString n) +private theorem synthesis_repeatedValue (s : Set (BooleanFunction n)) + (f : BitString n → BitString n) (T K : ℕ) (lo hi : BitString n → BitVec w) (hlo : ∀ i : Fin w, (fun x => (lo x).getLsbD i.val) ∈ s) (hhi : ∀ i : Fin w, (fun x => (hi x).getLsbD i.val) ∈ s) diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Depth.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Depth.lean index 5fa0327c2..0b0ff68af 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Depth.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Depth.lean @@ -205,7 +205,7 @@ theorem depth_from_checkpoints (c : Circuit signature n n) (L : ℕ) (hL : 0 < L nlinarith /-- The depth construction is within `50000` times the fixed-power tradeoff. -/ -theorem depthCost_le (n s M L : ℕ) (hL : 0 < L) (hLN : L ≤ 2 ^ n) (hM : M ≤ 2 ^ n / L) : +private theorem depthCost_le (n s M L : ℕ) (hL : 0 < L) (hLN : L ≤ 2 ^ n) (hM : M ≤ 2 ^ n / L) : depthCost n s M L ≤ 50000 * powerBudget n s (2 ^ n) L := by unfold depthCost powerBudget set N := 2 ^ n with hNdef diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/DepthSearch.lean b/Complexity/Computability/Circuit/Boolean/Iteration/DepthSearch.lean index e4cd43edb..726124feb 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/DepthSearch.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/DepthSearch.lean @@ -64,7 +64,7 @@ def searchBelow (n μ : ℕ) : ℕ → ℕ | j + 1 => if searchBelow n μ j + 2 ^ (n - j - 1) < μ then searchBelow n μ j + 2 ^ (n - j - 1) else searchBelow n μ j -theorem searchBelow_bounds (n μ : ℕ) (hμ : μ ≤ 2 ^ n) (j : ℕ) (hj : j ≤ n) : +private theorem searchBelow_bounds (n μ : ℕ) (hμ : μ ≤ 2 ^ n) (j : ℕ) (hj : j ≤ n) : (μ = 0 → searchBelow n μ j = 0) ∧ (0 < μ → searchBelow n μ j < μ ∧ μ ≤ searchBelow n μ j + 2 ^ (n - j)) := by induction j with @@ -83,7 +83,8 @@ theorem searchBelow_bounds (n μ : ℕ) (hμ : μ ≤ 2 ^ n) (j : ℕ) (hj : j rw [searchBelow, show n - (j + 1) = n - j - 1 by omega] split_ifs <;> constructor <;> omega -theorem searchBelow_lt (n μ j : ℕ) (hμ : μ < 2 ^ n) (hj : j ≤ n) : searchBelow n μ j < 2 ^ n := by +private theorem searchBelow_lt (n μ j : ℕ) (hμ : μ < 2 ^ n) (hj : j ≤ n) : + searchBelow n μ j < 2 ^ n := by obtain ⟨hz, hp⟩ := searchBelow_bounds n μ hμ.le j hj rcases Nat.eq_zero_or_pos μ with h | h · rw [hz h] @@ -236,7 +237,7 @@ theorem depth_circuit (c : Circuit signature n n) (L : ℕ) (hL : 0 < L) (hLN : omega /-- The threshold search costs at most a factor `(n + 1) ^ 2` more than a fixed power. -/ -theorem depthBudget_le (n s L : ℕ) : +private theorem depthBudget_le (n s L : ℕ) : depthBudget n s L ≤ 200000 * (n + 1) ^ 2 * powerBudget n s (2 ^ n) L := by set B := powerBudget n s (2 ^ n) L have hb : (n + 1) ^ 3 ≤ B := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Encoded.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Encoded.lean index 9e482d27d..30ae8f94f 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Encoded.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Encoded.lean @@ -43,7 +43,7 @@ universe u variable {α : Type u} {n : ℕ} /-- A circuit realizing `f` on the encodings of an invariant set realizes its powers. -/ -theorem iterate_encoded (f : α → α) (S : Finset α) (e : α → BitString n) +private theorem iterate_encoded (f : α → α) (S : Finset α) (e : α → BitString n) (c : Circuit signature n n) (hS : ∀ x ∈ S, f x ∈ S) (hstep : ∀ x ∈ S, c.eval interpretation (e x) = e (f x)) {x : α} (hx : x ∈ S) (T : ℕ) : (c.eval interpretation)^[T] (e x) = e (f^[T] x) := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Eventual.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Eventual.lean index acc515b7b..5da2db9c9 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Eventual.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Eventual.lean @@ -120,7 +120,7 @@ theorem recurring_target_circuit (c : Circuit signature n n) (p : Circuit signat omega /-- Negating a one-bit circuit costs one gate. -/ -theorem exists_not_circuit (p : Circuit signature n 1) : +private theorem exists_not_circuit (p : Circuit signature n 1) : ∃ out : Circuit signature n 1, (∀ x, out.eval interpretation x 0 = !p.eval interpretation x 0) ∧ out.size ≤ p.size + 1 := by have hp : Synthesis interpretation (inputs n) {fun x => p.eval interpretation x 0} p.size := diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/ForestCircuitRecords.lean b/Complexity/Computability/Circuit/Boolean/Iteration/ForestCircuitRecords.lean index 657cfd7e6..257b76a12 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/ForestCircuitRecords.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/ForestCircuitRecords.lean @@ -80,7 +80,7 @@ def forestHighWord (r : BitString (n + 1 + (n + 1))) : BitVec (n + 1) := forestHighWord (forestLabelWord low high x) = BitVec.ofNat (n + 1) (high x).val := by simp only [forestHighWord, forestLabelWord, Fin.append_right, word_getLsbD] -theorem forestLowWord_toNat (low high : BitString n → Fin (Nat.card (BitString n))) +private theorem forestLowWord_toNat (low high : BitString n → Fin (Nat.card (BitString n))) (x : BitString n) : (forestLowWord (forestLabelWord low high x)).toNat = (low x).val := by have hlt : (low x).val < 2 ^ n := by @@ -88,7 +88,7 @@ theorem forestLowWord_toNat (low high : BitString n → Fin (Nat.card (BitString have hpow : 2 ^ (n + 1) = 2 * 2 ^ n := by rw [pow_succ'] rw [forestLowWord_bits, BitVec.toNat_ofNat, Nat.mod_eq_of_lt (by omega)] -theorem forestHighWord_toNat (low high : BitString n → Fin (Nat.card (BitString n))) +private theorem forestHighWord_toNat (low high : BitString n → Fin (Nat.card (BitString n))) (x : BitString n) : (forestHighWord (forestLabelWord low high x)).toNat = (high x).val := by have hlt : (high x).val < 2 ^ n := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/InPlace.lean b/Complexity/Computability/Circuit/Boolean/Iteration/InPlace.lean index a24828e6e..33c01d342 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/InPlace.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/InPlace.lean @@ -136,7 +136,7 @@ theorem writeHeads_of_forall_ne (w : Fin n → Γ) (p : Fin h → Fin n) (σ : F exact ih (fun j => p j.castSucc) (fun j => σ j.castSucc) (fun j => hi _) /-- Rewriting the symbols read leaves the tape unchanged. -/ -theorem writeHeads_read (w : Fin n → Γ) (p : Fin h → Fin n) : +private theorem writeHeads_read (w : Fin n → Γ) (p : Fin h → Fin n) : writeHeads w p (fun j => w (p j)) = w := by induction h with | zero => rfl @@ -204,7 +204,7 @@ theorem reach_card_le_configs : card_config (Q := Q) (Γ := Γ) (n := n) (h := h) ▸ Finset.card_le_univ _ /-- Reachable configurations are covered by the first `B` steps from every input. -/ -theorem reach_card_le_of_cover (B : ℕ) +private theorem reach_card_le_of_cover (B : ℕ) (hcover : ∀ (x : BitString n) (t : ℕ), ∃ y, ∃ j < B, M.step^[t] (M.init x) = M.step^[j] (M.init y)) : (reach M n).card ≤ 2 ^ n * B := by @@ -233,7 +233,7 @@ theorem reach_card_le_time (hM : M.HaltingAbsorbing) (t : ℕ) omit [Fintype Q] [Fintype Γ] in /-- Running `τ * m` steps of a machine with rounds of length `τ` runs `m` rounds. -/ -theorem iterate_rounds (τ : ℕ) (P : BitString n → BitString n) +private theorem iterate_rounds (τ : ℕ) (P : BitString n → BitString n) (hround : ∀ x, M.step^[τ] (M.init x) = M.init (P x)) (x : BitString n) (m : ℕ) : M.step^[τ * m] (M.init x) = M.init (P^[m] x) := by induction m with @@ -300,7 +300,8 @@ section Circuits variable [Fintype Q] [Fintype Γ] [NeZero n] {w : ℕ} (M : Machine Q Γ h) /-- The reachable set fits in the encoding width. -/ -theorem reach_card_le_two_pow (e : Config Q Γ n h → BitString w) (he : Set.InjOn e (reach M n)) : +private theorem reach_card_le_two_pow (e : Config Q Γ n h → BitString w) + (he : Set.InjOn e (reach M n)) : (reach M n).card ≤ 2 ^ w := by classical rw [← Finset.card_image_of_injOn he] diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/InputTime.lean b/Complexity/Computability/Circuit/Boolean/Iteration/InputTime.lean index 9ab5187fa..849b992d6 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/InputTime.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/InputTime.lean @@ -76,7 +76,7 @@ theorem inputTimeIterate_zero (f : BitString n → BitString n) (y : BitString ( simp only [inputTimeIterate, h, Function.iterate_zero, id_eq] /-- Reading one more bit of a binary time adds that bit's power of two. -/ -theorem toNat_word_mod_two_pow_succ (bits : BitString m) {j : ℕ} (hj : j < m) : +private theorem toNat_word_mod_two_pow_succ (bits : BitString m) {j : ℕ} (hj : j < m) : (word bits).toNat % 2 ^ (j + 1) = (word bits).toNat % 2 ^ j + if bits ⟨j, hj⟩ then 2 ^ j else 0 := by have hbit : (word bits).toNat / 2 ^ j % 2 = if bits ⟨j, hj⟩ then 1 else 0 := by @@ -92,7 +92,7 @@ theorem toNat_word_mod_two_pow_succ (bits : BitString m) {j : ℕ} (hj : j < m) split_ifs <;> simp /-- Applying `f^[2 ^ j]` exactly when bit `j` is set extends the time read so far by that bit. -/ -theorem iterate_toNat_word_mod_two_pow_succ {α : Type*} (f : α → α) (bits : BitString m) +private theorem iterate_toNat_word_mod_two_pow_succ {α : Type*} (f : α → α) (bits : BitString m) {j : ℕ} (hj : j < m) (y : α) : f^[(word bits).toNat % 2 ^ (j + 1)] y = if bits ⟨j, hj⟩ then f^[2 ^ j] (f^[(word bits).toNat % 2 ^ j] y) diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Label.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Label.lean index 754086c90..99b8b454e 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Label.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Label.lean @@ -200,7 +200,7 @@ variable (f : BitString n → BitString n) (K : ℕ) {x : BitString n} (hx : x ∈ Function.periodicPts f) (hK : cycleLength f x ≤ K) include hx hK in -theorem shortRepresentative_eq : shortRepresentative f K x = canonicalCycle f x := by +private theorem shortRepresentative_eq : shortRepresentative f K x = canonicalCycle f x := by have hs := scanMin_spec (fun j : Fin (K + 1) => f^[j.val] x) x (K + 1) apply @le_antisymm _ (lexOrder n).toPartialOrder · have ht := canonicalTime_lt_cycleLength f x hx @@ -214,7 +214,7 @@ theorem shortRepresentative_eq : shortRepresentative f K x = canonicalCycle f x exact iterate_mem_cycleSet f hx j.val include hx hK in -theorem shortLength_eq : shortLength (w := w) f K x = BitVec.ofNat w (cycleLength f x) := by +private theorem shortLength_eq : shortLength (w := w) f K x = BitVec.ofNat w (cycleLength f x) := by have hmin : Function.minimalPeriod f x = cycleLength f x := (cycleLength_eq_minimalPeriod_of_mem_periodicPts f hx).symm apply firstIndex_spec _ ⟨cycleLength f x, by omega⟩ @@ -231,7 +231,7 @@ theorem shortLength_eq : shortLength (w := w) f K x = BitVec.ofNat w (cycleLengt exact absurd hi (not_lt.mpr hm) include hx hK in -theorem shortTime_eq : shortTime (w := w) f K x = BitVec.ofNat w (canonicalTime f x) := by +private theorem shortTime_eq : shortTime (w := w) f K x = BitVec.ofNat w (canonicalTime f x) := by unfold shortTime rw [shortRepresentative_eq f K hx hK] exact firstIndex_spec _ ⟨canonicalTime f x, (canonicalTime_lt_cycleLength f x hx).trans_le diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/LabelCircuit.lean b/Complexity/Computability/Circuit/Boolean/Iteration/LabelCircuit.lean index c0e724c6d..828882afe 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/LabelCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/LabelCircuit.lean @@ -161,7 +161,7 @@ theorem cyclic_labels_from_checkpoints (c : Circuit signature n n) (L : ℕ) (hL omega /-- The label construction is within `20000` times the fixed-power tradeoff. -/ -theorem labelCost_le (n s M L : ℕ) (hL : 0 < L) (hLN : L ≤ 2 ^ n) (hM : M ≤ 2 ^ n / L) : +private theorem labelCost_le (n s M L : ℕ) (hL : 0 < L) (hLN : L ≤ 2 ^ n) (hM : M ≤ 2 ^ n / L) : labelCost n s M L ≤ 20000 * powerBudget n s (2 ^ n) L := by unfold labelCost powerBudget set N := 2 ^ n with hNdef @@ -224,7 +224,7 @@ theorem cyclic_label_circuit (c : Circuit signature n n) (L : ℕ) (hL : 0 < L) exact ⟨out, hout, hs.trans (labelCost_le _ _ _ _ hL hLN (by simpa using hcard))⟩ /-- Moving a state onto its cycle with `f^[(2 ^ n)!]` does not change its label. -/ -theorem canonicalLabel_iterate_factorial (f : BitString n → BitString n) (x : BitString n) : +private theorem canonicalLabel_iterate_factorial (f : BitString n → BitString n) (x : BitString n) : canonicalLabel f (f^[(2 ^ n).factorial] x) = canonicalLabel f x := by have hd := Nat.dvd_factorial (cycleLength_pos f x) (cycleLength_le_two_pow f x) simp only [canonicalLabel, canonicalCycle_iterate, cycleLength_iterate, phase_iterate, diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/LongTime.lean b/Complexity/Computability/Circuit/Boolean/Iteration/LongTime.lean index 19afeaecf..bf8972c71 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/LongTime.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/LongTime.lean @@ -102,7 +102,8 @@ theorem toNat_compressedTime (f : BitString n → BitString n) (x : BitString n) /-- Compressing an available time with an available cycle length: one streaming remainder over the time bits, one modular difference, one addition, one comparison and one selection. -/ -theorem synthesis_compressedTime (s : Set (BooleanFunction a)) (ell : BitString a → BitVec (n + 3)) +private theorem synthesis_compressedTime (s : Set (BooleanFunction a)) + (ell : BitString a → BitVec (n + 3)) (bits : BitString a → BitString m) (hl : wordWires ell ⊆ s) (hb : ∀ j, (fun x => bits x j) ∈ s) (hc : ∀ b : Bool, (fun _ : BitString a => b) ∈ s) : Synthesis interpretation s (wordWires fun x => compressedTime n (ell x) (bits x)) @@ -137,14 +138,14 @@ theorem synthesis_compressedTime (s : Set (BooleanFunction a)) (ell : BitString /-- The gate count of the long-time construction: constants, the label circuit, the time compression and binary powering over `n + 3` time bits. -/ -def longTimeBudget (n s m L : ℕ) : ℕ := +private def longTimeBudget (n s m L : ℕ) : ℕ := 2 + 60000 * powerBudget n s (2 ^ n) L + (m * (22 * (n + 3) + 3) + 50 * (n + 4) ^ 2 + 16 * (n + 3) + 1 + (5 * m + 2)) + (n + 3) * (40000 * powerBudget n s (2 ^ n) L + 4 * n) /-- **Long input times**, for times wider than the state: some circuit of size at most `longTimeBudget n c.size m L` iterates `c` for a number of steps given by `m > n` input bits. -/ -theorem long_time_circuit (c : Circuit signature n n) (m L : ℕ) (hnm : n < m) (hL : 0 < L) +private theorem long_time_circuit (c : Circuit signature n n) (m L : ℕ) (hnm : n < m) (hL : 0 < L) (hLN : L ≤ 2 ^ n) : ∃ out : Circuit signature (n + m) n, out.Computes interpretation (inputTimeIterate (c.eval interpretation) m) ∧ @@ -192,7 +193,7 @@ theorem long_time_circuit (c : Circuit signature n n) (m L : ℕ) (hnm : n < m) simp only [time, ell, canonicalLabel, labelLength_labelBits] rw [toNat_compressedTime f _ _ hnm, iterate_normalizedTime] -theorem longTimeBudget_le (n s m L : ℕ) : +private theorem longTimeBudget_le (n s m L : ℕ) : longTimeBudget n s m L ≤ 200000 * (n + 1) * powerBudget n s (2 ^ n) L + 80 * m * (n + 1) := by set B := powerBudget n s (2 ^ n) L diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter.lean b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter.lean index 9ea6cb753..2f54fe112 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter.lean @@ -142,7 +142,7 @@ theorem mem_easyCounterPowers (k q : ℕ) (T : Fin (ModulusCounter.period k)) : simp only [easyCounterPowers, Finset.mem_filter, Finset.mem_univ, true_and, Circuit.mem_functionsAtMost_iff] -theorem easyCounterPowers_card_le (k q : ℕ) : +private theorem easyCounterPowers_card_le (k q : ℕ) : (easyCounterPowers k q).card ≤ signature.orderedBudget (k + k) (k + k) q := by classical have hsub : (easyCounterPowers k q).image (fun T => ModulusCounter.power (k := k) T.val) ⊆ @@ -170,7 +170,7 @@ theorem hardCounterPowers_card_ge (k q : ℕ) : /-- The description budget at `lowerBudget k` leaves an additive margin of `2 ^ (k - 1)` in the binary exponent. -/ -theorem lowerBudget_description_margin (k : ℕ) (hk : 64 ≤ k) : +private theorem lowerBudget_description_margin (k : ℕ) (hk : 64 ≤ k) : let q := lowerBudget k 3 * q + (k + 2) * (2 * q + (k + k) + 1) + k + 2 ^ (k - 1) ≤ 2 ^ k - 1 := by dsimp only diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Basic.lean b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Basic.lean index 7c71eea67..28fd14125 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Basic.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Basic.lean @@ -139,12 +139,12 @@ theorem iterate_power (T : ℕ) : (power (k := k) 1)^[T] = power T := by /-- The order `lcm(1, …, 2 ^ k - 1)` common to every active `k`-bit modular counter. -/ def period (k : ℕ) : ℕ := Nat.lcmUpto (2 ^ k - 1) -theorem modulus_dvd_period {a : ℕ} (ha : 0 < a) (haU : a < 2 ^ k) : a ∣ period k := by +private theorem modulus_dvd_period {a : ℕ} (ha : 0 < a) (haU : a < 2 ^ k) : a ∣ period k := by change a ∣ (Finset.Icc 1 (2 ^ k - 1)).lcm id apply Finset.dvd_lcm simpa only [Finset.mem_Icc] using (show 1 ≤ a ∧ a ≤ 2 ^ k - 1 by omega) -theorem power_period (x : BitString (k + k)) : power (period k) x = x := by +private theorem power_period (x : BitString (k + k)) : power (period k) x = x := by unfold power advance split_ifs with h · have hd := modulus_dvd_period h.1 (BitVec.isLt (leftWord x)) @@ -220,7 +220,8 @@ theorem stepValue_spec (a b : BitVec k) : simp /-- Equality of two available `k`-bit words costs at most `6 * k + 1` gates. -/ -theorem synthesis_word_eq {n : ℕ} (s : Set (BooleanFunction n)) (a b : BitString n → BitVec k) +private theorem synthesis_word_eq {n : ℕ} (s : Set (BooleanFunction n)) + (a b : BitString n → BitVec k) (ha : ∀ i : Fin k, (fun x => (a x).getLsbD i.val) ∈ s) (hb : ∀ i : Fin k, (fun x => (b x).getLsbD i.val) ∈ s) : Synthesis interpretation s {fun x => decide (a x = b x)} (6 * k + 1) := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Remainders.lean b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Remainders.lean index 48667f354..ae3c115de 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Remainders.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/ModulusCounter/Remainders.lean @@ -297,7 +297,7 @@ def counterOutput (y : BitString (k + k)) : BitString k := (ModulusCounter.rightWord (counterInput x)).toNat = 0 := by simp [counterInput] -theorem counterRemainder_spec (T : ℕ) (x : BitString k) : +private theorem counterRemainder_spec (T : ℕ) (x : BitString k) : counterOutput ((counterStep k)^[T] (counterInput x)) = ModulusCounter.remainder T x := by rw [counterStep, ModulusCounter.iterate_power] funext i diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/NavigationWord.lean b/Complexity/Computability/Circuit/Boolean/Iteration/NavigationWord.lean index f05a1d99f..792f8fd5f 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/NavigationWord.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/NavigationWord.lean @@ -108,7 +108,7 @@ theorem toNat_navigationGap (x y : BitString n) rw [navigationGap, BitVec.toNat_sub_of_le (by rw [BitVec.le_def]; simpa using hle), toNat_depthWord, toNat_depthWord] -theorem toNat_navigationDistance (x y : BitString n) : +private theorem toNat_navigationDistance (x y : BitString n) : (navigationDistance f x y).toNat = cyclicDistance f x y := by have hμ := transientDepth_lt_two_pow f x have hpx := (phase_lt f x).trans_le (cycleLength_le_two_pow f x) diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/PrimeCycles.lean b/Complexity/Computability/Circuit/Boolean/Iteration/PrimeCycles.lean index 9a535bed6..7cc777b78 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/PrimeCycles.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/PrimeCycles.lean @@ -139,7 +139,7 @@ theorem lcmBelow_add_dvd {m n : ℕ} (h : n ≤ m) : exact hpow omega -theorem lcmBelow_add_le {m n : ℕ} (h : n ≤ m) : +private theorem lcmBelow_add_le {m n : ℕ} (h : n ≤ m) : lcmBelow (m + n) ≤ lcmBelow m * (m + n).choose m := Nat.le_of_dvd (Nat.mul_pos (lcmBelow_pos m) (Nat.choose_pos (Nat.le_add_right m n))) (lcmBelow_add_dvd h) @@ -243,7 +243,7 @@ variable (ℓ : BitVec m → ℕ) funext x simp [power] -theorem power_add (hℓ : ∀ r, ℓ r < 2 ^ K) (S T : ℕ) (x : BitString (m + K)) : +private theorem power_add (hℓ : ∀ r, ℓ r < 2 ^ K) (S T : ℕ) (x : BitString (m + K)) : power ℓ T (power ℓ S x) = power ℓ (S + T) x := by simp only [power, classWord_pack, posWord_pack, BitVec.toNat_ofNat] rw [Nat.mod_eq_of_lt (advance_lt (hℓ _) (BitVec.isLt _)), advance_add] @@ -256,7 +256,7 @@ theorem iterate_step (hℓ : ∀ r, ℓ r < 2 ^ K) (T : ℕ) : | zero => simp | succ T ih => rw [Function.iterate_succ_apply', ih, step, power_add ℓ hℓ] -theorem advance_mod (a b T : ℕ) : advance a b (T % a) = advance a b T := by +private theorem advance_mod (a b T : ℕ) : advance a b (T % a) = advance a b T := by unfold advance split_ifs with h · rw [Nat.add_mod, Nat.mod_mod, ← Nat.add_mod] @@ -271,7 +271,7 @@ theorem power_apply_mod (T : ℕ) (r : BitVec m) (b : BitVec K) : rfl /-- Every positive length divides the product of positive lengths, so that power is the identity. -/ -theorem power_prod_eq_id : +private theorem power_prod_eq_id : power (K := K) ℓ (∏ r ∈ Finset.univ.filter (fun r => 0 < ℓ r), ℓ r) = id := by funext x simp only [power, id] @@ -328,7 +328,7 @@ theorem order_pos : 0 < order ℓ := have := (Finset.mem_filter.mp hr).2 omega -theorem dvd_order {r : BitVec m} (hr : 1 < ℓ r) : ℓ r ∣ order ℓ := +private theorem dvd_order {r : BitVec m} (hr : 1 < ℓ r) : ℓ r ∣ order ℓ := Finset.dvd_prod_of_mem _ (Finset.mem_filter.mpr ⟨Finset.mem_univ _, hr⟩) /-- Pairwise coprimality of the nontrivial cycle lengths. -/ @@ -392,7 +392,7 @@ theorem card_range_iterate (hℓ : ∀ r, ℓ r < 2 ^ K) (hc : LengthsCoprime simp /-- The order is at least `L ^ c` when the `c` nontrivial lengths are each at least `L`. -/ -theorem pow_card_le_order {L : ℕ} (hL : ∀ r, 1 < ℓ r → L ≤ ℓ r) : +private theorem pow_card_le_order {L : ℕ} (hL : ∀ r, 1 < ℓ r → L ≤ ℓ r) : L ^ (active ℓ).card ≤ order ℓ := Finset.pow_card_le_prod _ _ _ fun r hr => hL r (Finset.mem_filter.mp hr).2 @@ -425,14 +425,14 @@ def classPrime (m g : ℕ) (f : ℕ → ℕ) (r : BitVec m) : ℕ := if h : ∃ z, z < 2 ^ g ∧ (candidate g f r z).Prime then candidate g f r (Nat.find h) else 1 -theorem candidate_mod {g : ℕ} (f : ℕ → ℕ) (r : BitVec m) {z : ℕ} (hz : z < 2 ^ g) : +private theorem candidate_mod {g : ℕ} (f : ℕ → ℕ) (r : BitVec m) {z : ℕ} (hz : z < 2 ^ g) : candidate g f r z % 2 ^ g = z := by unfold candidate rw [pow_add, Nat.add_mod, Nat.add_mod (2 ^ m * 2 ^ g), Nat.mul_mod_left, Nat.mul_mod_left, Nat.mod_eq_of_lt hz] simp [Nat.mod_eq_of_lt hz] -theorem candidate_bounds {g : ℕ} {f : ℕ → ℕ} (hf : ∀ z, f z < 2 ^ m) (r : BitVec m) +private theorem candidate_bounds {g : ℕ} {f : ℕ → ℕ} (hf : ∀ z, f z < 2 ^ m) (r : BitVec m) {z : ℕ} (hz : z < 2 ^ g) : 2 ^ (m + g) ≤ candidate g f r z ∧ candidate g f r z < 2 ^ (m + g + 1) := by have hx : r.toNat ^^^ f z < 2 ^ m := Nat.xor_lt_two_pow r.isLt (hf z) @@ -455,7 +455,7 @@ theorem candidate_injective {g : ℕ} (f : ℕ → ℕ) {r s : BitVec m} {y z : simp only [Nat.xor_assoc, Nat.xor_self, Nat.xor_zero] at this exact BitVec.eq_of_toNat_eq this -theorem classPrime_spec {g : ℕ} (f : ℕ → ℕ) (r : BitVec m) : +private theorem classPrime_spec {g : ℕ} (f : ℕ → ℕ) (r : BitVec m) : classPrime m g f r = 1 ∨ ∃ z < 2 ^ g, classPrime m g f r = candidate g f r z ∧ (classPrime m g f r).Prime := by classical diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Record.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Record.lean index 99b07cecc..2360b26b1 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Record.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Record.lean @@ -108,7 +108,7 @@ theorem encode_injective : Function.Injective (encode : Record n w → BitString Function.LeftInverse.injective decode_encode /-- The sort key of a decoded record is read from its key coordinates. -/ -theorem key_decode (bits : BitString (width n w)) : +private theorem key_decode (bits : BitString (width n w)) : (decode bits).key = toLex (bits ∘ keyBits) := by apply congrArg toLex funext i @@ -152,13 +152,13 @@ def initial (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M else if j.val - M ≤ K then query (f^[j.val - M] x) (j.val - M) else pad -theorem initial_stored (f : BitString n → BitString n) (T K : ℕ) +private theorem initial_stored (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (hR : M + (K + 1) ≤ R) (j : Fin M) : initial (R := R) (w := w) f T K checkpoints x ⟨j.val, by have := j.isLt; omega⟩ = stored (checkpoints j) (f^[T - K] (checkpoints j)) := by simp [initial, j.isLt] -theorem initial_query (f : BitString n → BitString n) (T K : ℕ) +private theorem initial_query (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (hR : M + (K + 1) ≤ R) (j : Fin (K + 1)) : initial (R := R) (w := w) f T K checkpoints x ⟨M + j.val, by have := j.isLt; omega⟩ = @@ -171,7 +171,7 @@ def Valid (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → r = pad ∨ (∃ h : Fin M, r = stored (checkpoints h) (f^[T - K] (checkpoints h))) ∨ ∃ d ≤ K, r = query (f^[d] x) d -theorem valid_initial (f : BitString n → BitString n) (T K : ℕ) +private theorem valid_initial (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (j : Fin R) : Valid f T K checkpoints x (initial (w := w) f T K checkpoints x j) := by unfold initial @@ -196,7 +196,7 @@ inductive Witness (f : BitString n → BitString n) (T K : ℕ) (checkpoints : F Witness f T K checkpoints x (query (f^[i] x) i) (query (f^[j] x) j) /-- A collision between valid records is a witness, without requiring unique records. -/ -theorem collision_witness (f : BitString n → BitString n) (T K : ℕ) +private theorem collision_witness (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (a b : Record n w) (ha : Valid f T K checkpoints x a) (hb : Valid f T K checkpoints x b) (hc : collision a b = true) : Witness f T K checkpoints x a b := by @@ -230,13 +230,13 @@ def sorted (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) : fun j => decode (directProductInput ((bitonicSortCircuit keyBits d true).eval interpretation (pack records)) j) -theorem sorted_perm (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) : +private theorem sorted_perm (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) : (List.ofFn (sorted d records)).Perm (List.ofFn records) := by have h := (bitonicSortCircuit_perm (keyBits (n := n) (w := w)) d true (pack records)).map decode unfold sorted simpa only [List.map_ofFn, Function.comp_def, directProductInput_pack, decode_encode] using h -theorem monotone_key_sorted (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) : +private theorem monotone_key_sorted (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) : Monotone (key ∘ sorted d records) := by have h := monotone_bitonicSortCircuit (keyBits (n := n) (w := w)) d (pack records) simpa only [Function.comp_def, sorted, key_decode] using h @@ -252,7 +252,7 @@ def detect (records : Fin R → Record n w) : Record n w × Record n w := /-- A checkpoint hit or a repeat of the prefix gives two different initial records with equal keys, the first of which is not padding. -/ -theorem initial_collision (f : BitString n → BitString n) (T K : ℕ) +private theorem initial_collision (f : BitString n → BitString n) (T K : ℕ) (checkpoints : Fin M → BitString n) (x : BitString n) (hR : M + (K + 1) ≤ R) (hK : K < 2 ^ w) (hcover : (∃ d ≤ K, ∃ h : Fin M, f^[d] x = checkpoints h) ∨ ∃ i j, i < j ∧ j ≤ K ∧ f^[i] x = f^[j] x) : @@ -277,7 +277,7 @@ theorem initial_collision (f : BitString n → BitString n) (T K : ℕ) omega /-- Sorting turns such a pair into a flagged adjacent pair. -/ -theorem sorted_has_collision (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) +private theorem sorted_has_collision (d : ℕ) (records : Fin (BitonicSort.arity d) → Record n w) (hex : ∃ a b, records a ≠ records b ∧ (records a).key = (records b).key ∧ (records a).padding = false) : ∃ j : Fin (BitonicSort.arity d - 1), diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/RecordCircuit.lean b/Complexity/Computability/Circuit/Boolean/Iteration/RecordCircuit.lean index 13849a3db..2740f95c8 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/RecordCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/RecordCircuit.lean @@ -115,7 +115,7 @@ theorem payload_mem {s : Set (BooleanFunction n)} {a : BitString n → Record n (ha : wireSet a ⊆ s) (i : Fin n) : (fun x => (a x).payload i) ∈ s := by simpa [encode] using ha ⟨Fin.natAdd (n + 1) (Fin.natAdd w i).succ, rfl⟩ -theorem synthesis_collision (s : Set (BooleanFunction n)) (a b : BitString n → Record n w) +private theorem synthesis_collision (s : Set (BooleanFunction n)) (a b : BitString n → Record n w) (ha : wireSet a ⊆ s) (hb : wireSet b ⊆ s) : Synthesis interpretation s {fun x => collision (a x) (b x)} (20 * (width n w + 1)) := by have hs := synthesis_bits_eq s (fun x => (a x).state) (fun x => (b x).state) diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Remainder.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Remainder.lean index 3e6d9429a..6d5524d87 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Remainder.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Remainder.lean @@ -61,7 +61,7 @@ namespace Cslib.Circuits.Boolean.Iteration variable {n a m w : ℕ} /-- A word with one more bit, read from the least significant end. -/ -theorem word_succ (bits : BitString (m + 1)) : +private theorem word_succ (bits : BitString (m + 1)) : word bits = (word fun i : Fin m => bits i.succ).concat (bits 0) := by apply BitVec.eq_of_getLsbD_eq intro i hi @@ -85,7 +85,7 @@ def streamRemainder (d : BitVec w) : {m : ℕ} → BitString m → BitVec w | 0, _ => 0 | _ + 1, bits => remainderStep d (streamRemainder d fun i => bits i.succ) (bits 0) -theorem toNat_remainderStep (d r : BitVec w) (b : Bool) (hd : 0 < d.toNat) +private theorem toNat_remainderStep (d r : BitVec w) (b : Bool) (hd : 0 < d.toNat) (hw : 2 * d.toNat ≤ 2 ^ w) (hr : r.toNat < d.toNat) : (remainderStep d r b).toNat = (2 * r.toNat + b.toNat) % d.toNat := by have hb : b.toNat ≤ 1 := Bool.toNat_le b @@ -118,7 +118,7 @@ theorem toNat_streamRemainder (d : BitVec w) (bits : BitString m) (hd : 0 < d.to simp only [Nat.add_mod, Nat.mul_mod, Nat.mod_mod, Nat.mul_comm] /-- One step of long division: a subtraction, a comparison and a selection. -/ -theorem synthesis_remainderStep (s : Set (BooleanFunction a)) (d r : BitString a → BitVec w) +private theorem synthesis_remainderStep (s : Set (BooleanFunction a)) (d r : BitString a → BitVec w) (b : BooleanFunction a) (hd : ∀ i : Fin w, (fun x => (d x).getLsbD i.val) ∈ s) (hr : ∀ i : Fin w, (fun x => (r x).getLsbD i.val) ∈ s) (hb : b ∈ s) : Synthesis interpretation s (wordWires fun x => remainderStep (d x) (r x) (b x)) @@ -217,7 +217,7 @@ def subMod (a b d : BitVec w) : BitVec w := let rb := streamRemainder d fun i : Fin w => b.getLsbD i.val if ra.ult rb then ra + d - rb else ra - rb -theorem add_sub_mod_mod_eq_ite (a b d : ℕ) (hd : 0 < d) : +private theorem add_sub_mod_mod_eq_ite (a b d : ℕ) (hd : 0 < d) : (a + d - b % d) % d = if a % d < b % d then a % d + d - b % d else a % d - b % d := by have ha := Nat.mod_lt a hd have hb := Nat.mod_lt b hd diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Residue.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Residue.lean index 75e0996c0..636ff33ff 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Residue.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Residue.lean @@ -52,7 +52,7 @@ namespace Cslib.Circuits.Boolean.Iteration def liftResidue (lower period r : ℕ) : ℕ := if r < lower then r + period else r /-- Repeated correction preserves the residue and never passes the interval. -/ -theorem liftResidue_invariant (lower period r t : ℕ) (hp : 0 < period) (hr : r < period) : +private theorem liftResidue_invariant (lower period r t : ℕ) (hp : 0 < period) (hr : r < period) : let v := (liftResidue lower period)^[t] r (lower ≤ v ∨ t ≤ v) ∧ v < lower + period ∧ v % period = r := by induction t with @@ -70,7 +70,7 @@ theorem liftResidue_invariant (lower period r t : ℕ) (hp : 0 < period) (hr : r · exact ⟨Or.inl (by omega), ih.2⟩ /-- Enough corrections place the residue in the interval. -/ -theorem liftResidue_spec (lower period T K : ℕ) (hp : 0 < period) (hK : lower ≤ K) : +private theorem liftResidue_spec (lower period T K : ℕ) (hp : 0 < period) (hK : lower ≤ K) : let v := (liftResidue lower period)^[K] (T % period) lower ≤ v ∧ v < lower + period ∧ v % period = T % period := by have h := liftResidue_invariant lower period (T % period) K hp (Nat.mod_lt _ hp) @@ -89,7 +89,7 @@ def liftWord {w : ℕ} (lower period r : BitVec w) : BitVec w := if r.ult lower then r + period else r /-- The word correction agrees with the natural-number one when the interval fits. -/ -theorem liftWord_toNat {w : ℕ} (lower period r : BitVec w) +private theorem liftWord_toNat {w : ℕ} (lower period r : BitVec w) (hfit : lower.toNat + period.toNat ≤ 2 ^ w) : (liftWord lower period r).toNat = liftResidue lower.toNat period.toNat r.toNat := by unfold liftWord liftResidue @@ -98,7 +98,7 @@ theorem liftWord_toNat {w : ℕ} (lower period r : BitVec w) exact Nat.mod_eq_of_lt (by omega) · simp only [BitVec.ult, hr, decide_false, Bool.false_eq_true, ↓reduceIte] -theorem liftWord_iterate_toNat {w : ℕ} (lower period r : BitVec w) +private theorem liftWord_iterate_toNat {w : ℕ} (lower period r : BitVec w) (hfit : lower.toNat + period.toNat ≤ 2 ^ w) (K : ℕ) : ((liftWord lower period)^[K] r).toNat = (liftResidue lower.toNat period.toNat)^[K] r.toNat := by @@ -112,7 +112,7 @@ def residueWord {w : ℕ} (T K : ℕ) (period : BitVec w) : BitVec w := word (selectBits period fun j : Fin (K + 1) => fun i : Fin w => (BitVec.ofNat w (T % j.val)).getLsbD i.val) -theorem residueWord_toNat {w T K : ℕ} (period : BitVec w) +private theorem residueWord_toNat {w T K : ℕ} (period : BitVec w) (hK : K < 2 ^ w) (hp : 0 < period.toNat) (hpK : period.toNat ≤ K) : (residueWord T K period).toNat = T % period.toNat := by rw [residueWord, selectBits_of_toNat_lt _ _ (by omega), word_getLsbD, @@ -136,7 +136,7 @@ theorem repeatWordIndex_spec {α : Type*} {f : α → α} {x : α} {w T K : ℕ} exact liftResidue_reconstructs hlt heq (by omega) (by omega) /-- One word correction: an addition, a comparison and a multiplexer. -/ -theorem synthesis_liftWord {n w : ℕ} (s : Set (BooleanFunction n)) +private theorem synthesis_liftWord {n w : ℕ} (s : Set (BooleanFunction n)) (lower period r : BitString n → BitVec w) (hl : ∀ i : Fin w, (fun x => (lower x).getLsbD i.val) ∈ s) (hp : ∀ i : Fin w, (fun x => (period x).getLsbD i.val) ∈ s) @@ -152,7 +152,7 @@ theorem synthesis_liftWord {n w : ℕ} (s : Set (BooleanFunction n)) (by dsimp +zetaDelta [Synthesis.Builder.add, Synthesis.Builder.start]; omega) /-- Iterated word corrections, sharing all intermediate words. -/ -theorem synthesis_liftWord_iterate {n w : ℕ} (s : Set (BooleanFunction n)) +private theorem synthesis_liftWord_iterate {n w : ℕ} (s : Set (BooleanFunction n)) (lower period init : BitString n → BitVec w) (hl : ∀ i : Fin w, (fun x => (lower x).getLsbD i.val) ∈ s) (hp : ∀ i : Fin w, (fun x => (period x).getLsbD i.val) ∈ s) @@ -171,7 +171,7 @@ theorem synthesis_liftWord_iterate {n w : ℕ} (s : Set (BooleanFunction n)) (fun i => Or.inr (Synthesis.subset_stages q le_rfl ⟨i, rfl⟩)) /-- A residue table costs only its word width and entry count, whatever `T` is. -/ -theorem synthesis_residueWord {n w : ℕ} (s : Set (BooleanFunction n)) +private theorem synthesis_residueWord {n w : ℕ} (s : Set (BooleanFunction n)) (T K : ℕ) (period : BitString n → BitVec w) (hp : ∀ i : Fin w, (fun x => (period x).getLsbD i.val) ∈ s) (hconst : ∀ b : Bool, (fun _ : BitString n => b) ∈ s) : diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Scan.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Scan.lean index 5d7c6b63e..8f588ca83 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Scan.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Scan.lean @@ -101,7 +101,7 @@ variable {n a R w : ℕ} open Classical in /-- Lexicographic comparison of two available bit strings, by the native comparison formula. -/ -theorem synthesis_lexLt (s : Set (BooleanFunction a)) (x y : BitString a → BitString n) +private theorem synthesis_lexLt (s : Set (BooleanFunction a)) (x y : BitString a → BitString n) (hx : wires x ⊆ s) (hy : wires y ⊆ s) : Synthesis interpretation s {fun z => decide (toLex (x z) < toLex (y z))} (6 * n + 1) := by have h := Synthesis.circuit (I := interpretation) (s := s) @@ -157,7 +157,7 @@ theorem synthesis_scanMin (s : Set (BooleanFunction a)) (values : BitString a /-! ### First flagged positions -/ /-- If position `j` is flagged and no later position below `t` is, the scan returns its record. -/ -theorem chooseRecord_eq_of_last {α : Type*} (flags : Fin R → Bool) (records : Fin R → α) +private theorem chooseRecord_eq_of_last {α : Type*} (flags : Fin R → Bool) (records : Fin R → α) (fallback : α) (j : Fin R) (hj : flags j = true) (t : ℕ) (hjt : j.val < t) (hlast : ∀ i : Fin R, j.val < i.val → i.val < t → flags i = false) : chooseRecord flags records fallback t = records j := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/Selection.lean b/Complexity/Computability/Circuit/Boolean/Iteration/Selection.lean index 35d171bc2..8166daa3a 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/Selection.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/Selection.lean @@ -58,7 +58,7 @@ variable {β : Type v} [LinearOrder β] /-- In an array with monotone keys, two different records with equal keys force an adjacent pair of different records with that key. -/ -theorem adjacent_distinct_of_equal_keys (records : Fin R → α) (key : α → β) +private theorem adjacent_distinct_of_equal_keys (records : Fin R → α) (key : α → β) (hs : Monotone (key ∘ records)) (i j : Fin R) (hij : i < j) (hne : records i ≠ records j) (heq : key (records i) = key (records j)) : ∃ (p : ℕ) (hp : p + 1 < R), diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/SequentialSquaring.lean b/Complexity/Computability/Circuit/Boolean/Iteration/SequentialSquaring.lean index 91bd9f4ec..f8449ac90 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/SequentialSquaring.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/SequentialSquaring.lean @@ -64,7 +64,7 @@ theorem carmichael_pos (M : ℕ) : 0 < carmichael M := Nat.pos_of_ne_zero Monoid.exponent_ne_zero_of_finite /-- Modulo a prime divisor `p` of `M`, every residue satisfies `y ^ (λ(M) + 1) = y`. -/ -theorem pow_carmichael_succ_prime {M p : ℕ} [NeZero M] (hp : p.Prime) (hpM : p ∣ M) +private theorem pow_carmichael_succ_prime {M p : ℕ} [NeZero M] (hp : p.Prime) (hpM : p ∣ M) (y : ZMod p) : y ^ (carmichael M + 1) = y := by have := Fact.mk hp by_cases hy : y = 0 @@ -96,7 +96,7 @@ theorem pow_carmichael_succ {M : ℕ} (hM : Squarefree M) (x : ZMod M) : rwa [Nat.prod_primeFactors_of_squarefree hM] at key /-- Adding a multiple of `λ(M)` to a positive exponent does not change the power map. -/ -theorem pow_add_mul_carmichael {M : ℕ} (hM : Squarefree M) (x : ZMod M) {a : ℕ} +private theorem pow_add_mul_carmichael {M : ℕ} (hM : Squarefree M) (x : ZMod M) {a : ℕ} (ha : 1 ≤ a) (k : ℕ) : x ^ (a + carmichael M * k) = x ^ a := by induction k with | zero => simp diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/SparseDisplacement.lean b/Complexity/Computability/Circuit/Boolean/Iteration/SparseDisplacement.lean index 7e9d5322f..89a5a6171 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/SparseDisplacement.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/SparseDisplacement.lean @@ -61,7 +61,7 @@ def thresholdSum (S : Finset ℕ) (coeff : ℕ → BitVec w) (base x : BitVec w) base + ∑ i ∈ S, if (BitVec.ofNat w i).ult x then coeff i else 0 /-- Each threshold uses one comparison, one word selector, and one shared-carry addition. -/ -theorem synthesis_thresholdSum (S : Finset ℕ) (coeff : ℕ → BitVec w) (base : BitVec w) +private theorem synthesis_thresholdSum (S : Finset ℕ) (coeff : ℕ → BitVec w) (base : BitVec w) (s : Set (BitString n → Bool)) (a : BitString n → BitVec w) (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) (hc : ∀ b : Bool, (fun _ : BitString n => b) ∈ s) : @@ -148,7 +148,7 @@ theorem thresholdSum_displacement (h : BitVec n → BitVec n) (x : BitVec n) : simp [d] /-- Counter-coordinate changes inject into the commutation-defect set. -/ -theorem displacementCuts_card (f h : BitVec n → BitVec n) +private theorem displacementCuts_card (f h : BitVec n → BitVec n) (hc : Function.Commute h f) (hi : Function.Injective h) : (displacementCuts h).card ≤ 2 * (disagreement f (fun x => x + 1)).card := by classical @@ -167,7 +167,7 @@ theorem displacementCuts_card (f h : BitVec n → BitVec n) simpa only [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hi', Nat.mod_eq_of_lt hj'] using he' /-- A sparse derivative gives an actual native Boolean circuit, including all selection gates. -/ -theorem displacement_circuit (h : BitVec n → BitVec n) : +private theorem displacement_circuit (h : BitVec n → BitVec n) : ∃ out : Circuit Boolean.signature n n, out.Computes Boolean.interpretation (fun x i => (h (word x)).getLsbD i.val) ∧ out.size ≤ 2 + (displacementCuts h).card * (21 * n + 3) + (12 * n + 1) := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/SparseNavigation.lean b/Complexity/Computability/Circuit/Boolean/Iteration/SparseNavigation.lean index 36ae6b8c3..be7f2e1b2 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/SparseNavigation.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/SparseNavigation.lean @@ -63,7 +63,7 @@ def cycleLabelVisits (x y : BitString (n + (chartWidth n + chartWidth n))) : (fun i => ((cycleLabelDistance x y).setWidth (n + 1)).getLsbD i.val)) (fun i => ((labelLength y).setWidth (n + 1)).getLsbD i.val) -theorem cycleLabelVisits_flag (f : BitVec n → BitVec n) (hf : Function.Injective f) +private theorem cycleLabelVisits_flag (f : BitVec n → BitVec n) (hf : Function.Injective f) (x y : BitVec n) : cycleLabelVisits (wordCycleLabel f x) (wordCycleLabel f y) (Fin.castAdd (n + 1) (0 : Fin (1 + (n + 1)))) = true ↔ ∃ t, f^[t] x = y := by @@ -78,7 +78,7 @@ theorem cycleLabelVisits_flag (f : BitVec n → BitVec n) (hf : Function.Injecti rw [decide_eq_true_eq] exact (exists_iterate_eq_iff_canonicalCycle_eq f x y (hf.mem_periodicPts y)).symm -theorem cycleLabelDistance_toNat (f : BitVec n → BitVec n) (hf : Function.Injective f) +private theorem cycleLabelDistance_toNat (f : BitVec n → BitVec n) (hf : Function.Injective f) (x y : BitVec n) (hc : canonicalCycle f x = canonicalCycle f y) : (cycleLabelDistance (wordCycleLabel f x) (wordCycleLabel f y)).toNat = cyclicDistance f x y := by @@ -95,7 +95,7 @@ theorem cycleLabelDistance_toNat (f : BitVec n → BitVec n) (hf : Function.Inje (by rw [hp, he]; exact phase_lt f x), hp, hp, he] simp only [cyclicDistance, hdepth, Nat.add_zero] -theorem cycleLabelVisits_first (f : BitVec n → BitVec n) (hf : Function.Injective f) +private theorem cycleLabelVisits_first (f : BitVec n → BitVec n) (hf : Function.Injective f) (x y : BitVec n) (hr : ∃ t, f^[t] x = y) : let d := (visitScheduleFirst (cycleLabelVisits (wordCycleLabel f x) (wordCycleLabel f y))).toNat f^[d] x = y ∧ (∀ j < d, f^[j] x ≠ y) ∧ d < 2 ^ n := by @@ -114,7 +114,7 @@ theorem cycleLabelVisits_first (f : BitVec n → BitVec n) (hf : Function.Inject exact ⟨by simpa only [hdepth, Nat.zero_add] using hfirst.1, by simpa only [hdepth, Nat.zero_add] using hfirst.2, hd⟩ -theorem cycleLabelVisits_period (f : BitVec n → BitVec n) (hf : Function.Injective f) +private theorem cycleLabelVisits_period (f : BitVec n → BitVec n) (hf : Function.Injective f) (x y : BitVec n) : (visitSchedulePeriod (cycleLabelVisits (wordCycleLabel f x) (wordCycleLabel f y))).toNat = Function.minimalPeriod f y := by diff --git a/Complexity/Computability/Circuit/Boolean/Iteration/UniversalMap.lean b/Complexity/Computability/Circuit/Boolean/Iteration/UniversalMap.lean index b0bffe13c..9cab08bde 100644 --- a/Complexity/Computability/Circuit/Boolean/Iteration/UniversalMap.lean +++ b/Complexity/Computability/Circuit/Boolean/Iteration/UniversalMap.lean @@ -93,7 +93,7 @@ def hardwired {n m : ℕ} (place : Fin m → Fin n ⊕ Bool) (x : BitString n) : fun j => Sum.elim x id (place j) /-- Hardwiring constants and duplicating or permuting inputs costs the two constants. -/ -theorem exists_hardwired_comp {n m p : ℕ} (u : Circuit signature m p) +private theorem exists_hardwired_comp {n m p : ℕ} (u : Circuit signature m p) (place : Fin m → Fin n ⊕ Bool) : ∃ d : Circuit signature n p, (∀ x, d.eval interpretation x = u.eval interpretation (hardwired place x)) ∧ @@ -105,7 +105,7 @@ theorem exists_hardwired_comp {n m p : ℕ} (u : Circuit signature m p) exact le_rfl /-- Hardwire constants, run `u`, and read selected output wires. -/ -theorem exists_hardwired_projection {n m p k : ℕ} (u : Circuit signature m p) +private theorem exists_hardwired_projection {n m p k : ℕ} (u : Circuit signature m p) (place : Fin m → Fin n ⊕ Bool) (select : Fin k → Fin p) : ∃ d : Circuit signature n k, (∀ x, d.eval interpretation x = @@ -337,7 +337,7 @@ def start (D : Description σ n G) (x : Fin n → V) : Config σ V n G := ⟨D, x, fun _ => default, 0⟩ /-- The widened lines of a program read only earlier gates. -/ -theorem lines_wire_lt {g : ℕ} (p : Program σ n g) (j : Fin g) : +private theorem lines_wire_lt {g : ℕ} (p : Program σ n g) (j : Fin g) : ∀ (a : Fin (σ.Arity (p.lines j).op)) (b : Fin g), (p.lines j).wires a = Wire.gate b → b.val < j.val := by induction p with @@ -370,7 +370,7 @@ theorem lines_wire_lt {g : ℕ} (p : Program σ n g) (j : Fin g) : simpa using ih j a b' hw /-- Reading a wire by its index, from work registers that hold the gate values. -/ -theorem read_wireIndex {g : ℕ} (x : Fin n → V) (w : Fin G → V) (e : Fin g → V) +private theorem read_wireIndex {g : ℕ} (x : Fin n → V) (w : Fin G → V) (e : Fin g → V) (wire : Wire n g) (hlt : ∀ b : Fin g, wire = Wire.gate b → b.val < G) (hw : ∀ (b : Fin g) (h : b.val < G), wire = Wire.gate b → w ⟨b, h⟩ = e b) : read x w (wireIndex wire) = Wire.elim x e wire := by diff --git a/Complexity/Computability/Circuit/Boolean/KarchmerWigderson.lean b/Complexity/Computability/Circuit/Boolean/KarchmerWigderson.lean index 980661238..224205878 100644 --- a/Complexity/Computability/Circuit/Boolean/KarchmerWigderson.lean +++ b/Complexity/Computability/Circuit/Boolean/KarchmerWigderson.lean @@ -85,7 +85,7 @@ namespace Formula /-- The protocol of a formula finds a bit where Alice's and Bob's inputs differ, when the formula is `onAlice` on Alice's input and `!onAlice` on Bob's. -/ -theorem differsAt_run_kwProtocol [NeZero n] (F : Formula signature n) (onAlice : Bool) +private theorem differsAt_run_kwProtocol [NeZero n] (F : Formula signature n) (onAlice : Bool) {x y : BitString n} (hx : F.eval interpretation x = onAlice) (hy : F.eval interpretation y = !onAlice) : DiffersAt x y ((F.kwProtocol onAlice).run x y) := by @@ -267,7 +267,7 @@ theorem exists_kwProtocol_of_computes [NeZero n] {f : BooleanFunction n} /-- A protocol for the Karchmer–Wigderson game of `f` gives a formula computing `f`, with at most as many AND and OR gates on a path as the protocol sends bits. -/ -theorem exists_formula_of_solves {f : BooleanFunction n} {p : KWProtocol (Fin n)} +private theorem exists_formula_of_solves {f : BooleanFunction n} {p : KWProtocol (Fin n)} (hp : p.Solves DiffersAt {x | f x = true} {y | f y = false}) : ∃ F : Formula signature n, F.Computes interpretation f ∧ F.depthWith binaryCost ≤ p.depth := by refine ⟨p.kwFormula {x | f x = true} {y | f y = false}, fun x => ?_, diff --git a/Complexity/Computability/Circuit/Boolean/KeyedSort.lean b/Complexity/Computability/Circuit/Boolean/KeyedSort.lean index d2708c28a..fe0a97c65 100644 --- a/Complexity/Computability/Circuit/Boolean/KeyedSort.lean +++ b/Complexity/Computability/Circuit/Boolean/KeyedSort.lean @@ -118,7 +118,7 @@ theorem antitone_keyedSortCircuit (key : Circuit signature r k) (depth : ℕ) ((keyedSortCircuit.pack key depth).eval interpretation x) /-- Key computation is charged once per record; packing and dropping keys are free wirings. -/ -theorem cost_program_keyedSortCircuit (key : Circuit signature r k) (depth : ℕ) +private theorem cost_program_keyedSortCircuit (key : Circuit signature r k) (depth : ℕ) (ascending : Bool) (cost : signature.Op → ℕ) : (keyedSortCircuit key depth ascending).program.cost cost = BitonicSort.arity depth * key.program.cost cost + diff --git a/Complexity/Computability/Circuit/Boolean/Khrapchenko.lean b/Complexity/Computability/Circuit/Boolean/Khrapchenko.lean index 033d75edc..47d253f9d 100644 --- a/Complexity/Computability/Circuit/Boolean/Khrapchenko.lean +++ b/Complexity/Computability/Circuit/Boolean/Khrapchenko.lean @@ -405,7 +405,7 @@ theorem eval_parityFormula (k o : ℕ) (h : o + 2 ^ k ≤ n) (x : BitString n) : omega /-- The formula `parityFormula k o` has leaf size `4 ^ k`. -/ -theorem leafSize_parityFormula (k o : ℕ) (h : o + 2 ^ k ≤ n) : +private theorem leafSize_parityFormula (k o : ℕ) (h : o + 2 ^ k ≤ n) : (parityFormula k o h).leafSize = 4 ^ k := by induction k generalizing o with | zero => rfl diff --git a/Complexity/Computability/Circuit/Boolean/Layered/Compile/Correctness.lean b/Complexity/Computability/Circuit/Boolean/Layered/Compile/Correctness.lean index 1004dde27..0d54a1412 100644 --- a/Complexity/Computability/Circuit/Boolean/Layered/Compile/Correctness.lean +++ b/Complexity/Computability/Circuit/Boolean/Layered/Compile/Correctness.lean @@ -178,7 +178,7 @@ private theorem schedule_correct (p : Program signature n g) (x : Fin n → Bool exact hvalues w hw /-- Every compiled reference reads an available preceding-layer wire, including at depth zero. -/ -theorem wellFormed_schedule (p : Program signature n g) (k : ℕ) : +private theorem wellFormed_schedule (p : Program signature n g) (k : ℕ) : WellFormed n (schedule n p.code (wireDepthsCode n p.code) k) := (schedule_correct p (fun _ => false) k).1 diff --git a/Complexity/Computability/Circuit/Boolean/Layered/Padding.lean b/Complexity/Computability/Circuit/Boolean/Layered/Padding.lean index b032dcd92..eec7163b9 100644 --- a/Complexity/Computability/Circuit/Boolean/Layered/Padding.lean +++ b/Complexity/Computability/Circuit/Boolean/Layered/Padding.lean @@ -44,7 +44,8 @@ def identityLayer (width : ℕ) : List Node := (List.range width).map Node.copy @[simp] theorem length_identityLayer (width : ℕ) : (identityLayer width).length = width := by simp [identityLayer] -theorem valid_identityLayer (width : ℕ) : ∀ node ∈ identityLayer width, node.Valid width := by +private theorem valid_identityLayer (width : ℕ) : + ∀ node ∈ identityLayer width, node.Valid width := by intro node hnode obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hnode exact List.mem_range.mp hi @@ -69,7 +70,7 @@ theorem valid_identityLayer (width : ℕ) : ∀ node ∈ identityLayer width, no | succ count ih => simp only [List.replicate_succ, outputWidth_cons, length_identityLayer, ih] -theorem wellFormed_replicate_identityLayer (width count : ℕ) : +private theorem wellFormed_replicate_identityLayer (width count : ℕ) : WellFormed width (List.replicate count (identityLayer width)) := by induction count with | zero => trivial diff --git a/Complexity/Computability/Circuit/Boolean/MachineSimulation.lean b/Complexity/Computability/Circuit/Boolean/MachineSimulation.lean index 98982bd63..a64fb0046 100644 --- a/Complexity/Computability/Circuit/Boolean/MachineSimulation.lean +++ b/Complexity/Computability/Circuit/Boolean/MachineSimulation.lean @@ -64,7 +64,7 @@ theorem cfgAt_succ (t : ℕ) (x : Fin n → Bool) : cfgAt tm (t + 1) x = tm.step runFrom_succ _ _ /-- A work head is within `t` cells of the origin after `t` steps. -/ -theorem abs_workTapePos_cfgAt_le (t : ℕ) (x : Fin n → Bool) (i : Fin k) : +private theorem abs_workTapePos_cfgAt_le (t : ℕ) (x : Fin n → Bool) (i : Fin k) : |(cfgAt tm t x).workTapePos i| ≤ t := abs_workTapePos_runFrom_le _ t i @@ -76,10 +76,10 @@ noncomputable def featureFn (t : ℕ) (φ : Feature k State) : BooleanFunction n omit [DecidableEq State] in /-- The input symbol at position `j` is `s`, as a Boolean function of the input. -/ -def inputIs (j : ℕ) (s : Option Bool) : BooleanFunction n := +private def inputIs (j : ℕ) (s : Option Bool) : BooleanFunction n := fun x => decide (inputAt (List.ofFn x) j = s) -theorem featureFn_eq_true {t : ℕ} {φ : Feature k State} {x : Fin n → Bool} : +private theorem featureFn_eq_true {t : ℕ} {φ : Feature k State} {x : Fin n → Bool} : featureFn tm t φ x = true ↔ φ.Holds (cfgAt tm t x) := decide_eq_true_iff @@ -101,7 +101,7 @@ noncomputable def basicFeatures (n T : ℕ) : Finset (Feature k State) := (Featu def featureCount (n T k : ℕ) (State : Type) [Fintype State] : ℕ := (Fintype.card State + 1) + (n + 2) + k * (2 * T + 1) + k * (2 * T + 1) * 3 + 4 -theorem card_basicFeatures_le (n T : ℕ) : +private theorem card_basicFeatures_le (n T : ℕ) : (basicFeatures (k := k) (State := State) n T).card ≤ featureCount n T k State := (List.toFinset_card_le _).trans (length_basic n T).le @@ -166,7 +166,7 @@ variable [Fintype State] {T t : ℕ} omit [DecidableEq State] [Fintype State] in /-- An input symbol, or a constant, costs at most one gate. -/ -theorem synthesis_inputIs (j : ℕ) (b : Option Bool) : +private theorem synthesis_inputIs (j : ℕ) (b : Option Bool) : Synthesis interpretation (inputs n) {inputIs j b} 1 := by by_cases hj : j = 0 ∨ n < j · refine Synthesis.of_forall_eq_const (decide (none = b)) fun x => ?_ @@ -189,7 +189,7 @@ theorem synthesis_inputIs (j : ℕ) (b : Option Bool) : fun x => by rw [hinput]; simp /-- The symbol read by a work head, from the heads and cells in the window. -/ -theorem synthesis_read (ht : t ≤ T) (i : Fin k) (s : Option Bool) : +private theorem synthesis_read (ht : t ≤ T) (i : Fin k) (s : Option Bool) : Synthesis interpretation (inputs n ∪ basicAt tm T t) {featureFn tm t (.read i s)} ((2 * T + 1) * 2 + 1) := by obtain ⟨g, hg, hsyn⟩ := Synthesis.exists_exists_mem (s := inputs n ∪ basicAt tm T t) (window T) @@ -205,7 +205,7 @@ theorem synthesis_read (ht : t ≤ T) (i : Fin k) (s : Option Bool) : simp only [Bool.and_eq_true, featureFn_eq_true] /-- The symbol read by the input head, from its position and the input bits. -/ -theorem synthesis_inRead (s : Option Bool) : +private theorem synthesis_inRead (s : Option Bool) : Synthesis interpretation (inputs n ∪ basicAt tm T t) {featureFn tm t (.inRead s)} ((n + 2) * 3 + 1) := by obtain ⟨g, hg, hsyn⟩ := Synthesis.exists_exists_mem (s := inputs n ∪ basicAt tm T t) @@ -222,7 +222,7 @@ theorem synthesis_inRead (s : Option Bool) : def readsCost (n k T : ℕ) : ℕ := k * 3 * ((2 * T + 1) * 2 + 1) + 3 * ((n + 2) * 3 + 1) /-- Phase 1: the symbols read, from the basic features and the inputs. -/ -theorem synthesis_reads (ht : t ≤ T) : +private theorem synthesis_reads (ht : t ≤ T) : Synthesis interpretation (inputs n ∪ basicAt tm T t) (readsAt tm t) (readsCost n k T) := by have hw := Synthesis.biUnion (I := interpretation) (s := inputs n ∪ basicAt tm T t) (Finset.univ : Finset (Fin k × Option Bool)) (fun p => {featureFn tm t (.read p.1 p.2)}) @@ -237,7 +237,7 @@ theorem synthesis_reads (ht : t ≤ T) : · simp [readsCost, Fintype.card_option] /-- The indicator of a situation, from the state and the symbols read. -/ -theorem synthesis_sit (y : Situation k State) : +private theorem synthesis_sit (y : Situation k State) : Synthesis interpretation (inputs n ∪ basicAt tm T t ∪ readsAt tm t) {featureFn tm t (.sit y)} (k + 3) := by have hread : ∀ φ, ((∃ i s, φ = Feature.read i s) ∨ ∃ s, φ = Feature.inRead s) → @@ -255,7 +255,7 @@ theorem synthesis_sit (y : Situation k State) : simp only [Bool.and_eq_true, hg, featureFn_eq_true, Finset.mem_univ, true_implies, and_assoc] /-- Phase 2: every situation indicator. -/ -theorem synthesis_sits : +private theorem synthesis_sits : Synthesis interpretation (inputs n ∪ basicAt tm T t ∪ readsAt tm t) (sitsAt tm t) (Fintype.card (Situation k State) * (k + 3)) := by refine (Synthesis.biUnion (I := interpretation) (Finset.univ : Finset (Situation k State)) @@ -273,7 +273,7 @@ def featureCost (k : ℕ) (State : Type) [Fintype State] : ℕ := (4 * Fintype.card (Situation k State) + 2) * (2 * 3 + 2) + 1 /-- Every basic feature of the next configuration, from the terms of its step equation. -/ -theorem synthesis_next (ht : t ≤ T) {φ : Feature k State} (hφ : φ ∈ basicFeatures n T) : +private theorem synthesis_next (ht : t ≤ T) {φ : Feature k State} (hφ : φ ∈ basicFeatures n T) : Synthesis interpretation (stepSources tm T t) {featureFn (n := n) tm (t + 1) φ} (featureCost k State) := by have hφ' := List.mem_toFinset.1 hφ @@ -313,7 +313,7 @@ theorem synthesis_next (ht : t ≤ T) {φ : Feature k State} (hφ : φ ∈ basic exact Nat.add_le_add_right (Nat.mul_le_mul_right _ this) _ /-- Phase 3: all basic features of the next configuration. -/ -theorem synthesis_nexts (ht : t ≤ T) : +private theorem synthesis_nexts (ht : t ≤ T) : Synthesis interpretation (stepSources (n := n) tm T t) (basicAt tm T (t + 1)) (featureCount n T k State * featureCost k State) := by refine (Synthesis.biUnion (I := interpretation) (basicFeatures n T) @@ -344,7 +344,7 @@ section Run variable [Fintype State] {T : ℕ} /-- The basic features at time `0`, which do not depend on the input. -/ -theorem synthesis_basic_zero : +private theorem synthesis_basic_zero : Synthesis interpretation (inputs n) (basicAt tm T 0) (featureCount n T k State) := by have h0 : ∀ x : Fin n → Bool, cfgAt tm 0 x = tm.initCfg (List.ofFn x) := fun _ => rfl refine (Synthesis.biUnion (I := interpretation) (basicFeatures n T) @@ -376,12 +376,12 @@ theorem synthesis_basic : ∀ t ≤ T, rwa [Nat.add_mul, one_mul, ← Nat.add_assoc] /-- The total cost of simulating `T` steps on inputs of length `n`. -/ -def simulationCost (n T k : ℕ) (State : Type) [Fintype State] : ℕ := +private def simulationCost (n T k : ℕ) (State : Type) [Fintype State] : ℕ := featureCount n T k State + T * stepCost n T k State omit [DecidableEq State] in /-- The simulation cost is polynomially bounded when the number of steps is. -/ -theorem polynomiallyBounded_simulationCost {T : ℕ → ℕ} (hT : PolynomiallyBounded T) : +private theorem polynomiallyBounded_simulationCost {T : ℕ → ℕ} (hT : PolynomiallyBounded T) : PolynomiallyBounded fun n => simulationCost n (T n) k State := by simp only [simulationCost, featureCount, stepCost, readsCost, featureCost] fun_prop diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Fine.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Fine.lean index fa9b1176a..2b9477a2a 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Fine.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Fine.lean @@ -107,7 +107,8 @@ def PipelineSizeBound (A E : ℕ) : Prop := A * (2 ^ p + t * (s + 1) + copies * (s + 1) ^ ℓ) * (p + w + ℓ * b + Nat.log 2 (t + copies) + 2) ^ E -theorem pow_le_pow_add {B E E' : ℕ} {x : ℕ} (hx : x ≤ B) (hB : 1 ≤ B) : x ^ E ≤ B ^ (E + E') := +private theorem pow_le_pow_add {B E E' : ℕ} {x : ℕ} (hx : x ≤ B) (hB : 1 ≤ B) : + x ^ E ≤ B ^ (E + E') := (Nat.pow_le_pow_left hx E).trans (Nat.pow_le_pow_right hB (Nat.le_add_right E E')) /-- **The finite fine bound** at one input length. With a field of `2 ^ (h * m)` elements, diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/FineParameters.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/FineParameters.lean index e81e361ff..842b72a43 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/FineParameters.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/FineParameters.lean @@ -111,7 +111,7 @@ theorem mul_le_suffixWidth (hnd : num ≤ den) (n : ℕ) : have h1 : (X + 1) * (num + e) * n = n * (num + e + num * X) + X * e * n := by ring omega -theorem three_le_dimension : 3 ≤ dimension num den X := by +private theorem three_le_dimension : 3 ≤ dimension num den X := by unfold dimension omega @@ -144,7 +144,8 @@ theorem dimension_mul_fieldWidth_le (n : ℕ) : rw [Nat.sub_eq_zero_of_le (by omega), Nat.zero_div, Nat.mul_zero] /-- Linear growth eventually dominates any affine function of `log₂ (n + 2)`. -/ -theorem eventually_add_mul_log_le (A B : ℕ) : ∀ᶠ n in atTop, A + B * Nat.log 2 (n + 2) ≤ n := by +private theorem eventually_add_mul_log_le (A B : ℕ) : + ∀ᶠ n in atTop, A + B * Nat.log 2 (n + 2) ≤ n := by filter_upwards [Nat.eventually_mul_log_le (2 * B + 1) one_lt_two, eventually_ge_atTop (2 * (A + 2 * B) + 4)] with n hlog hn have h2 : Nat.log 2 (n + 2) ≤ Nat.log 2 n + 1 := by @@ -224,7 +225,7 @@ theorem eventually_add_depth_le (hnd : num < den) (c : ℕ) : omega /-- The prefix grows at least linearly: `n < (X + 1) * (prefixWidth n + 1)`. -/ -theorem lt_mul_prefixWidth_add_one (hden : 0 < den) (n : ℕ) : +private theorem lt_mul_prefixWidth_add_one (hden : 0 < den) (n : ℕ) : n < (X + 1) * (prefixWidth num den X n + 1) := by have F1 : n * (den + num * X) < (X + 1) * den * (prefixWidth num den X n + 1) := Nat.lt_mul_div_succ _ (Nat.mul_pos (by omega) hden) @@ -307,7 +308,7 @@ theorem mul_add_le_of_slack {P n w p den num R L O : ℕ} omega /-- Any polynomial is eventually below `2 ^ (n / c)`. -/ -theorem eventually_mul_pow_le_two_pow_div (A E c : ℕ) (hc : 0 < c) : +private theorem eventually_mul_pow_le_two_pow_div (A E c : ℕ) (hc : 0 < c) : ∀ᶠ n in atTop, A * (n + 1) ^ E ≤ 2 ^ (n / c) := by have htend : Tendsto (fun n : ℕ => n / c) atTop atTop := tendsto_atTop_atTop.mpr fun k => ⟨c * k, fun n hn => @@ -358,7 +359,7 @@ theorem eventually_mul_two_pow_dimension_le (hnd : num ≤ den) (X' : ℕ) : · simp [h] /-- The prefix leaves a linear number of suffix bits: `n / ((X + 1) den) ≤ suffixWidth n`. -/ -theorem div_le_suffixWidth (hnd : num < den) (hX : 0 < X) (n : ℕ) : +private theorem div_le_suffixWidth (hnd : num < den) (hX : 0 < X) (n : ℕ) : n / ((X + 1) * den) ≤ suffixWidth num den X n := by have h := mul_le_suffixWidth (X := X) hnd.le n have h1 : n ≤ X * (den - num) * n := Nat.le_mul_of_pos_left n (Nat.mul_pos hX (by omega)) diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/FineStatement.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/FineStatement.lean index f484abc5a..db8470c55 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/FineStatement.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/FineStatement.lean @@ -193,7 +193,7 @@ theorem exists_rat_coefficient {γ ε : ℝ} (hγ : 0 ≤ γ) (hγ1 : γ < 1) (h /-- A real copy budget `2 ^ (γ n)` below a rational exponent `num / den` is within the core budget `2 ^ (⌊num n / den⌋ + 1)`. -/ -theorem le_two_pow_of_real {γ : ℝ} {n k : ℕ} (hden : 0 < den) (hγ : γ ≤ (num : ℝ) / den) +private theorem le_two_pow_of_real {γ : ℝ} {n k : ℕ} (hden : 0 < den) (hγ : γ ≤ (num : ℝ) / den) (hk : (k : ℝ) ≤ (2 : ℝ) ^ (γ * n)) : k ≤ 2 ^ (num * n / den + 1) := by have hpos : 0 < (den : ℝ) := by exact_mod_cast hden have hq : (num : ℝ) * n < ((num * n / den + 1 : ℕ) : ℝ) * den := by diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Pipeline/Packing.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Pipeline/Packing.lean index 0f2bea41e..afb7af97f 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Pipeline/Packing.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Pipeline/Packing.lean @@ -85,7 +85,7 @@ variable {C : LineCode K ℓ} {place : BitString p ↪ Fin copies × C.info × F {f : BooleanFunction (p + w)} /-- The packed bit at a placed prefix is the value of `f` there. -/ -theorem packedBit_place (a : BitString p) (z : BitString w) : +private theorem packedBit_place (a : BitString p) (z : BitString w) : packedBit C place f z (place a).1 (place a).2.1 (place a).2.2 = f (Fin.append a z) := by apply Bool.eq_iff_iff.mpr rw [packedBit, decide_eq_true_iff] @@ -96,7 +96,7 @@ theorem packedBit_place (a : BitString p) (z : BitString w) : · exact fun hf => ⟨a, rfl, rfl, rfl, hf⟩ /-- Numbering the nonzero scalars by `scalar` sums over the punctured line. -/ -theorem sum_scalar {M : Type*} [AddCommMonoid M] (scalar : Fin s ≃ {c : K // c ≠ 0}) +private theorem sum_scalar {M : Type*} [AddCommMonoid M] (scalar : Fin s ≃ {c : K // c ≠ 0}) (g : K → M) : ∑ j, g (scalar j : K) = ∑ c ∈ (univ : Finset K).erase 0, g c := by rw [Finset.sum_subtype ((univ : Finset K).erase 0) (p := fun c => c ≠ 0) (fun c => by simp only [Finset.mem_erase, Finset.mem_univ, and_true]) g] diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler.lean index 733acf85e..0664cf515 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler.lean @@ -61,7 +61,7 @@ namespace Scheduler /-- Some circuit computes `finalOutput` exactly, by sorting the records by label and reading every request's line from the rank of its label, within the displayed number of gates. -/ -theorem exists_finalOutput_circuit (D L s : ℕ) : +private theorem exists_finalOutput_circuit (D L s : ℕ) : ∃ c : Circuit signature (2 ^ D * width D L s) (2 ^ D * (s * L)), c.Computes interpretation finalOutput ∧ c.size ≤ (D + 1) ^ 2 * 2 ^ D * (2 * D + 2 * width D L s + 1) := by @@ -94,7 +94,7 @@ theorem exists_finalOutput_circuit (D L s : ℕ) : /-- The phases with `2 ^ p, 2 ^ (p - 1), …, 1` pending requests accept every remaining request: some circuit maps every good state with `2 ^ D - 2 ^ p` accepted records to a good state with all records accepted, within `p + 1` phase budgets. -/ -theorem exists_phases_circuit (bits : K ≃+ BitString b) (scalar : Fin s ≃ {c : K // c ≠ 0}) +private theorem exists_phases_circuit (bits : K ≃+ BitString b) (scalar : Fin s ≃ {c : K // c ≠ 0}) (hmenu : ∀ k, 0 < k → k ≤ 2 ^ D → ∃ r, k * r ≤ 2 ^ D * (2 + 3 * (ℓ * b)) + 2 * k ∧ ∃ menu : Fin r → Fin k → Fin ℓ → K, IsUniversalMenu (2 ^ D) menu) (hs : s < 2 ^ b) (p : ℕ) (hp : p ≤ D) : diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/Phase.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/Phase.lean index 5c280eadf..9fad80abf 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/Phase.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/Phase.lean @@ -137,7 +137,7 @@ end Definitions variable {hk : a + arity p = 2 ^ D} /-- Pending request `i` sits `i` positions after the accepted block. -/ -theorem val_pending (i : Fin (arity p)) : (pending hk i).val = a + i.val := rfl +private theorem val_pending (i : Fin (arity p)) : (pending hk i).val = a + i.val := rfl /-- Accepted request `m` sits at position `m`. -/ theorem val_accepted (m : Fin a) : (accepted (p := p) hk m).val = m.val := rfl @@ -199,7 +199,7 @@ include htarget omit [Fintype K] [DecidableEq K] in /-- A candidate lists the bits of its point. -/ -theorem candidate_eq (e : Fin r) (i : Fin (arity p)) (c : Fin s) : +private theorem candidate_eq (e : Fin r) (i : Fin (arity p)) (c : Fin s) : candidate hk bits scalar menu x e i c = pointBits bits (T (pending hk i) + (scalar c : K) • menu e i) := by rw [candidate, htarget, pointBits_add] diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/PhaseCircuit.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/PhaseCircuit.lean index 5cf4bfaec..ffcb722b8 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/PhaseCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Scheduler/PhaseCircuit.lean @@ -69,7 +69,7 @@ private theorem add_false (x : Bool) : x + false = x := by cases x <;> rfl private theorem add_true (x : Bool) : x + true = !x := by cases x <;> rfl /-- Stage 1: each candidate bit is an input bit or its negation. -/ -theorem synthesis_candidate (hin : inputs _ ⊆ src) : +private theorem synthesis_candidate (hin : inputs _ ⊆ src) : Synthesis interpretation src (Set.range fun q : Fin r × Fin (arity p) × Fin s × Fin (ℓ * b) => fun x => candidate hk bits scalar menu x q.1 q.2.1 q.2.2.1 q.2.2.2) @@ -95,7 +95,7 @@ theorem synthesis_candidate (hin : inputs _ ⊆ src) : Nat.mul_assoc] /-- Stage 2: occupancy by one shared OR lookup among the accepted line points. -/ -theorem synthesis_occupied (hin : inputs _ ⊆ src) +private theorem synthesis_occupied (hin : inputs _ ⊆ src) (hcand : (Set.range fun q : Fin r × Fin (arity p) × Fin s × Fin (ℓ * b) => fun x => candidate hk bits scalar menu x q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ src) : Synthesis interpretation src @@ -154,7 +154,7 @@ theorem synthesis_occupied (hin : inputs _ ⊆ src) /-- Stage 3: for each menu entry, duplicate flags among its candidates. Padding records carry a true tag bit, so they never repeat a candidate. -/ -theorem synthesis_duplicate +private theorem synthesis_duplicate (hcand : (Set.range fun q : Fin r × Fin (arity p) × Fin s × Fin (ℓ * b) => fun x => candidate hk bits scalar menu x q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ src) : Synthesis interpretation src @@ -235,7 +235,7 @@ theorem synthesis_duplicate rfl /-- Stage 4: a request is clean when no candidate is occupied or a duplicate. -/ -theorem synthesis_clean +private theorem synthesis_clean (hocc : (Set.range fun q : Fin r × Fin (arity p) × Fin s => fun x => occupied hk bits scalar menu x q.1 q.2.1 q.2.2) ⊆ src) (hdup : (Set.range fun q : Fin r × Fin (arity p) × Fin s => @@ -259,7 +259,7 @@ theorem synthesis_clean /-- Stage 5: an entry succeeds when its sorted clean flags are true at position `⌈2 ^ p / 2⌉ - 1`. -/ -theorem synthesis_success +private theorem synthesis_success (hclean : (Set.range fun q : Fin r × Fin (arity p) => fun x => clean hk bits scalar menu x q.1 q.2) ⊆ src) : Synthesis interpretation src @@ -300,7 +300,7 @@ theorem synthesis_success · simp only [sum_const, card_univ, Fintype.card_fin, smul_eq_mul] /-- Stage 6: the first successful entry, from shared prefix disjunctions. -/ -theorem synthesis_chosen +private theorem synthesis_chosen (hsucc : (Set.range fun e : Fin r => fun x => success hk bits scalar menu x e) ⊆ src) : Synthesis interpretation src (Set.range fun e : Fin r => fun x => chosen hk bits scalar menu x e) (3 * r) := by @@ -338,7 +338,7 @@ theorem synthesis_chosen lia /-- Stage 7: the clean flag of each request for the chosen entry. -/ -theorem synthesis_flag +private theorem synthesis_flag (hchosen : (Set.range fun e : Fin r => fun x => chosen hk bits scalar menu x e) ⊆ src) (hclean : (Set.range fun q : Fin r × Fin (arity p) => fun x => clean hk bits scalar menu x q.1 q.2) ⊆ src) : @@ -358,7 +358,7 @@ theorem synthesis_flag · simp only [sum_const, card_univ, Fintype.card_fin, smul_eq_mul] /-- Stage 7: the candidate line of each request for the chosen entry. -/ -theorem synthesis_newLine +private theorem synthesis_newLine (hchosen : (Set.range fun e : Fin r => fun x => chosen hk bits scalar menu x e) ⊆ src) (hcand : (Set.range fun q : Fin r × Fin (arity p) × Fin s × Fin (ℓ * b) => fun x => candidate hk bits scalar menu x q.1 q.2.1 q.2.2.1 q.2.2.2) ⊆ src) : @@ -381,7 +381,7 @@ theorem synthesis_newLine Nat.mul_assoc] /-- Stage 8: the enriched pending records, sorted with clean records first. -/ -theorem synthesis_sortedPending (hin : inputs _ ⊆ src) +private theorem synthesis_sortedPending (hin : inputs _ ⊆ src) (hflag : (Set.range fun i : Fin (arity p) => fun x => flag hk bits scalar menu x i) ⊆ src) (hnew : (Set.range fun q : Fin (arity p) × Fin s × Fin (ℓ * b) => fun x => newLine hk bits scalar menu x q.1 q.2.1 q.2.2) ⊆ src) : diff --git a/Complexity/Computability/Circuit/Boolean/MassProduction/Uhlig.lean b/Complexity/Computability/Circuit/Boolean/MassProduction/Uhlig.lean index 1be283f0c..dba2c0d01 100644 --- a/Complexity/Computability/Circuit/Boolean/MassProduction/Uhlig.lean +++ b/Complexity/Computability/Circuit/Boolean/MassProduction/Uhlig.lean @@ -82,7 +82,8 @@ theorem layerOverhead_mono {p w w' : ℕ} (h : w ≤ w') : layerOverhead p w ≤ gcongr /-- A crude polynomial bound on the overhead of one pair. -/ -theorem layerOverhead_le (p w : ℕ) : layerOverhead p w ≤ 32 * 8 ^ p * (p + 1) * (w + 2) := by +private theorem layerOverhead_le (p w : ℕ) : + layerOverhead p w ≤ 32 * 8 ^ p * (p + 1) * (w + 2) := by have h8 : 8 ^ p = 2 ^ p * 2 ^ p * 2 ^ p := by rw [show 8 = 2 * 2 * 2 by rfl, mul_pow, mul_pow] unfold layerOverhead selectorCost @@ -144,7 +145,7 @@ theorem complexity_directProduct_two_pow_le {p m L H : ℕ} /-! ### Arithmetic estimates -/ /-- `(1 + 1 / M) ^ d ≤ 1 + 1 / R` when `(R + 1) d ≤ M`, without denominators. -/ -theorem mul_add_one_pow_le {R M d : ℕ} (h : (R + 1) * d ≤ M) : +private theorem mul_add_one_pow_le {R M d : ℕ} (h : (R + 1) * d ≤ M) : R * (M + 1) ^ d ≤ (R + 1) * M ^ d := by -- `(M + 1) ^ d * (M - d) ≤ M ^ (d + 1)` by induction. have key : ∀ e : ℕ, e ≤ M → (M + 1) ^ e * (M - e) ≤ M ^ (e + 1) := by @@ -205,7 +206,7 @@ theorem eventually_mul_complexity_single_le (Q : ℕ) : /-- The per-layer overhead with prefixes of `2 log₂ n + 2` bits is eventually below `2 ^ (n / 2)`, even after multiplication by `4 P n`. -/ -theorem eventually_overhead_le (P : ℕ) : ∀ᶠ n in atTop, +private theorem eventually_overhead_le (P : ℕ) : ∀ᶠ n in atTop, 4 * P * n * (32 * 8 ^ (2 * Nat.log 2 n + 2) * (2 * Nat.log 2 n + 3) * (n + 2)) ≤ 2 ^ (n / 2) := by have htend : Tendsto (fun n : ℕ => n / 2) atTop atTop := diff --git a/Complexity/Computability/Circuit/Boolean/Multiplicity.lean b/Complexity/Computability/Circuit/Boolean/Multiplicity.lean index c8f85c263..ed4b6c381 100644 --- a/Complexity/Computability/Circuit/Boolean/Multiplicity.lean +++ b/Complexity/Computability/Circuit/Boolean/Multiplicity.lean @@ -116,7 +116,7 @@ private theorem countP_eq_sum {α : Type*} (p : α → Bool) (l : List α) : | cons a l ih => cases h : p a <;> simp [h, ih, add_comm] /-- Reading the distinct wires with their multiplicities counts the true arguments. -/ -theorem multWeight_count_dedup {k : ℕ} (w : Fin k → Wire n g) (v : Wire n g → Bool) : +private theorem multWeight_count_dedup {k : ℕ} (w : Fin k → Wire n g) (v : Wire n g → Bool) : multWeight (fun j : Fin (List.ofFn w).dedup.length => (List.ofFn w).count (List.ofFn w).dedup[j.1]) (fun j => v (List.ofFn w).dedup[j.1]) = BitString.weight (v ∘ w) := by @@ -127,7 +127,7 @@ theorem multWeight_count_dedup {k : ℕ} (w : Fin k → Wire n g) (v : Wire n g rfl /-- Reading the distinct wires with their multiplicities keeps the number of arguments. -/ -theorem sum_count_dedup {k : ℕ} (w : Fin k → Wire n g) : +private theorem sum_count_dedup {k : ℕ} (w : Fin k → Wire n g) : ∑ j : Fin (List.ofFn w).dedup.length, (List.ofFn w).count (List.ofFn w).dedup[j.1] = k := by rw [Fin.sum_univ_fun_getElem (List.ofFn w).dedup (fun a => (List.ofFn w).count a), List.sum_map_count_dedup_eq_length, List.length_ofFn] @@ -168,7 +168,7 @@ theorem depth_multLine_le (line : Line extSignature n g) (depths : Wire n g → exact hle a /-- A line reading its distinct wires reads at most all `n + g` wires. -/ -theorem arity_multLine_le (line : Line extSignature n g) : +private theorem arity_multLine_le (line : Line extSignature n g) : multSignature.Arity (multLine line).op ≤ n + g := by obtain ⟨op, w⟩ := line cases op with diff --git a/Complexity/Computability/Circuit/Boolean/NaturalProof.lean b/Complexity/Computability/Circuit/Boolean/NaturalProof.lean index 4a21df9ff..511c60615 100644 --- a/Complexity/Computability/Circuit/Boolean/NaturalProof.lean +++ b/Complexity/Computability/Circuit/Boolean/NaturalProof.lean @@ -119,7 +119,7 @@ theorem truthTableTest_truthTable_eq_true_iff {C : Set (BooleanFunction n)} rw [truthTableTest_eq_true_iff, Equiv.symm_apply_apply] /-- The test deciding `C` accepts as many truth tables as there are functions in `C`. -/ -theorem card_filter_truthTableTest (C : Set (BooleanFunction n)) : +private theorem card_filter_truthTableTest (C : Set (BooleanFunction n)) : #{T | truthTableTest C T = true} = C.ncard := by have h : ((({T | truthTableTest C T = true} : Finset (BitString (2 ^ n))) : Set (BitString (2 ^ n)))) = truthTable n '' C := by @@ -193,7 +193,7 @@ theorem IsUseful.anti (hC : IsUseful Λ C) (hΛ : Λ' ⊆ Λ) (h : ∀ n, C' n /-- If `Λ` contains `SIZE s`, with `s` positive, a property useful against `Λ` eventually holds only for functions needing more than `s n` gates. -/ -theorem IsUseful.eventually_lt_complexity (hC : IsUseful Λ C) {s : ℕ → ℕ} (hΛ : SIZE s ⊆ Λ) +private theorem IsUseful.eventually_lt_complexity (hC : IsUseful Λ C) {s : ℕ → ℕ} (hΛ : SIZE s ⊆ Λ) (hs : ∀ n, 1 ≤ s n) : ∀ᶠ n in atTop, ∀ f ∈ C n, s n < complexity interpretation (single f) := by classical @@ -233,7 +233,7 @@ theorem isUseful_PPoly_iff : exact lt_irrefl _ (hn _ hmem) /-- A `P/poly`-constructive property is decided by circuits of size `2 ^ O(n)`. -/ -theorem exists_complexity_truthTableTest_le (hC : truthTableLanguage C ∈ PPoly) : +private theorem exists_complexity_truthTableTest_le (hC : truthTableLanguage C ∈ PPoly) : ∃ c, ∀ n, 1 ≤ n → complexity interpretation (single (truthTableTest (C n))) ≤ 2 ^ (c * n) := by obtain ⟨a, d, h⟩ := polynomiallyBounded_iff_le.1 hC refine ⟨a + 2 * d, fun n hn => ?_⟩ diff --git a/Complexity/Computability/Circuit/Boolean/Oracle.lean b/Complexity/Computability/Circuit/Boolean/Oracle.lean index 4629133ee..ff2f9604c 100644 --- a/Complexity/Computability/Circuit/Boolean/Oracle.lean +++ b/Complexity/Computability/Circuit/Boolean/Oracle.lean @@ -187,7 +187,8 @@ def PPolyOracle (A : Language Bool) : Set (Language Bool) := (C n).Computes (oracleInterpretation A) (single (L.slice n))} /-- A De Morgan program in the oracle basis has fan-in at most two. -/ -theorem fanInAtMost_mapOp_toOracle {g : ℕ} (p : Program signature n g) {r : ℕ} (hr : 2 ≤ r) : +private theorem fanInAtMost_mapOp_toOracle {g : ℕ} (p : Program signature n g) {r : ℕ} + (hr : 2 ≤ r) : (p.mapOp toOracle).FanInAtMost r := by induction p with | empty => trivial diff --git a/Complexity/Computability/Circuit/Boolean/Parity.lean b/Complexity/Computability/Circuit/Boolean/Parity.lean index 8fdd8a1e4..0432ad05f 100644 --- a/Complexity/Computability/Circuit/Boolean/Parity.lean +++ b/Complexity/Computability/Circuit/Boolean/Parity.lean @@ -50,7 +50,7 @@ def Program.appendXor (p : Program Boolean.signature n g) (u v : Wire n g) : ⟨.not, ![Wire.gate (Fin.last (g + 1))]⟩).gate ⟨.and, ![Wire.gate (Fin.last g).castSucc.castSucc, Wire.gate (Fin.last (g + 2))]⟩ -theorem Program.trace_appendXor (p : Program Boolean.signature n g) (u v : Wire n g) +private theorem Program.trace_appendXor (p : Program Boolean.signature n g) (u v : Wire n g) (x : BitString n) : (p.appendXor u v).trace Boolean.interpretation x (.gate (Fin.last (g + 3))) = (p.trace Boolean.interpretation x u ^^ p.trace Boolean.interpretation x v) := by @@ -78,7 +78,7 @@ def parityProgram : (k : ℕ) → k < n → Program signature n (4 * k) × Wire let pw := parityProgram k (by omega) (pw.1.appendXor pw.2 (.input ⟨k + 1, hk⟩), .gate (Fin.last _)) -theorem trace_parityProgram (k : ℕ) (hk : k < n) (x : BitString n) : +private theorem trace_parityProgram (k : ℕ) (hk : k < n) (x : BitString n) : (parityProgram k hk).1.trace interpretation x (parityProgram k hk).2 = parityOn (Iic ⟨k, hk⟩) x := by induction k with @@ -96,7 +96,7 @@ theorem trace_parityProgram (k : ℕ) (hk : k < n) (x : BitString n) : rw [this, parityOn_insert (by simp [Fin.le_def]), ← ih (by omega), Bool.xor_comm] exact Program.trace_appendXor _ _ _ x -theorem cost_parityProgram (k : ℕ) (hk : k < n) : +private theorem cost_parityProgram (k : ℕ) (hk : k < n) : (parityProgram k hk).1.cost binaryCost = 3 * k := by induction k with | zero => rfl diff --git a/Complexity/Computability/Circuit/Boolean/PolynomialTime.lean b/Complexity/Computability/Circuit/Boolean/PolynomialTime.lean index 00bf100b9..4ec6f1d34 100644 --- a/Complexity/Computability/Circuit/Boolean/PolynomialTime.lean +++ b/Complexity/Computability/Circuit/Boolean/PolynomialTime.lean @@ -121,13 +121,13 @@ theorem ofFn_substitute_frameWiring {n P : ℕ} (x : Fin n → Bool) (r : Fin P noncomputable def framedSlice (L : Language Bool) (n P : ℕ) : BooleanFunction (n + P) := fun y => L.slice (2 * n + 1 + P) (substitute (frameWiring n P) y) -theorem framedSlice_append_eq_true {L : Language Bool} {n P : ℕ} (x : Fin n → Bool) +private theorem framedSlice_append_eq_true {L : Language Bool} {n P : ℕ} (x : Fin n → Bool) (r : Fin P → Bool) : framedSlice L n P (Fin.append x r) = true ↔ frame (List.ofFn x) ++ List.ofFn r ∈ L := by rw [framedSlice, Language.slice_eq_true_iff, ofFn_substitute_frameWiring] /-- Framing costs at most two gates. -/ -theorem polynomiallyBounded_complexity_framedSlice {L : Language Bool} (hL : L ∈ PPoly) +private theorem polynomiallyBounded_complexity_framedSlice {L : Language Bool} (hL : L ∈ PPoly) {p : ℕ → ℕ} (hp : PolynomiallyBounded p) : PolynomiallyBounded fun n => complexity interpretation (single (framedSlice L n (p n))) := by set q := fun N => complexity interpretation (single (L.slice N)) with hq diff --git a/Complexity/Computability/Circuit/Boolean/Propagation.lean b/Complexity/Computability/Circuit/Boolean/Propagation.lean index 80eb00acc..f42fe6b7d 100644 --- a/Complexity/Computability/Circuit/Boolean/Propagation.lean +++ b/Complexity/Computability/Circuit/Boolean/Propagation.lean @@ -126,7 +126,7 @@ theorem eval_propagateCircuit_eq_true_iff {count : ℕ} (source link : BitString links ⟨index, hindex⟩ after (Nat.le_of_lt_succ before) /-- Each prefix contributes one AND and one OR, independently of the input links. -/ -theorem cost_propagateCircuit_program (count processed : ℕ) (fits : processed ≤ count) +private theorem cost_propagateCircuit_program (count processed : ℕ) (fits : processed ≤ count) (cost : signature.Op → ℕ) : (program count processed fits).cost cost = cost (.const false) + processed * (cost .and + cost .or) := by diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit.lean index 033a0c770..353dc2d42 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit.lean @@ -229,12 +229,12 @@ def subst (v : ℕ) (ℓ : Lit) : SemiCircuit where variable {C} -theorem eqnsHold_subst {v : ℕ} {ℓ : Lit} {val : ℕ → Bool} (h : val v = ℓ.eval val) : +private theorem eqnsHold_subst {v : ℕ} {ℓ : Lit} {val : ℕ → Bool} (h : val v = ℓ.eval val) : (C.subst v ℓ).EqnsHold val ↔ C.EqnsHold val := by unfold EqnsHold simp only [subst, Equation.holds_subst h] -theorem gatesHold_subst {v : ℕ} {ℓ : Lit} {val : ℕ → Bool} (h : val v = ℓ.eval val) : +private theorem gatesHold_subst {v : ℕ} {ℓ : Lit} {val : ℕ → Bool} (h : val v = ℓ.eval val) : (C.subst v ℓ).GatesHold val ↔ C.GatesHold val := by unfold GatesHold simp only [subst, Gate.eval_subst h] @@ -274,14 +274,15 @@ theorem size_subst (v : ℕ) (ℓ : Lit) : (C.subst v ℓ).size = C.size := rfl /-! ### Solutions of the affine system -/ -theorem Equation.holds_add_add {E : Equation} {val val' val'' : ℕ → Bool} (h : E.Holds val) +private theorem Equation.holds_add_add {E : Equation} {val val' val'' : ℕ → Bool} (h : E.Holds val) (h' : E.Holds val') (h'' : E.Holds val'') : E.Holds (val + val' + val'') := by unfold Equation.Holds at * simp only [Pi.add_apply, Finset.sum_add_distrib, h, h', h''] generalize E.rhs = r revert r; decide -theorem eqnsHold_add_add {val val' val'' : ℕ → Bool} (h : C.EqnsHold val) (h' : C.EqnsHold val') +private theorem eqnsHold_add_add {val val' val'' : ℕ → Bool} (h : C.EqnsHold val) + (h' : C.EqnsHold val') (h'' : C.EqnsHold val'') : C.EqnsHold (val + val' + val'') := fun e he => Equation.holds_add_add (h e he) (h' e he) (h'' e he) @@ -358,7 +359,7 @@ theorem AffineIn.unique (hC : C.WellFormed) {t : ℕ} {c c' : Bool} {T T' : Fins /-- A function of bits that depends only on the coordinates in `M` and preserves sums of three points is affine: a constant plus the sum of the coordinates in some `T ⊆ M`. -/ -theorem exists_affine_of_add_add {M : Finset ℕ} {g : (ℕ → Bool) → Bool} +private theorem exists_affine_of_add_add {M : Finset ℕ} {g : (ℕ → Bool) → Bool} (hcongr : ∀ u u' : ℕ → Bool, (∀ j ∈ M, u j = u' j) → g u = g u') (hadd : ∀ u u' u'' : ℕ → Bool, g (u + u' + u'') = g u + g u' + g u'') : ∃ T ⊆ M, ∀ u, g u = g 0 + ∑ j ∈ T, u j := by diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Equation.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Equation.lean index 5080fb52c..c8802c8ee 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Equation.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Equation.lean @@ -59,7 +59,7 @@ structure Equation where rhs : Bool /-- Adding `t` to a set of terms over `𝔽₂` removes it if present and inserts it otherwise. -/ -theorem symmDiff_singleton_eq (s : Finset ℕ) (t : ℕ) : +private theorem symmDiff_singleton_eq (s : Finset ℕ) (t : ℕ) : s ∆ {t} = if t ∈ s then s.erase t else insert t s := by ext z by_cases hz : z = t @@ -67,7 +67,7 @@ theorem symmDiff_singleton_eq (s : Finset ℕ) (t : ℕ) : split_ifs with h <;> simp [Finset.mem_symmDiff, h] · split_ifs <;> simp [Finset.mem_symmDiff, hz] -theorem sum_symmDiff_singleton (s : Finset ℕ) (t : ℕ) (val : ℕ → Bool) : +private theorem sum_symmDiff_singleton (s : Finset ℕ) (t : ℕ) (val : ℕ → Bool) : ∑ i ∈ s ∆ {t}, val i = ∑ i ∈ s, val i + val t := by rw [symmDiff_singleton_eq] split_ifs with ht @@ -82,7 +82,8 @@ theorem mem_symmDiff_singleton {s : Finset ℕ} {t z : ℕ} : z ∈ s ∆ {t} split_ifs with ht <;> simp [ht] · split_ifs with ht <;> simp [hz] -theorem card_symmDiff_singleton_le (s : Finset ℕ) (t : ℕ) : (s ∆ {t}).card ≤ s.card + 1 := by +private theorem card_symmDiff_singleton_le (s : Finset ℕ) (t : ℕ) : + (s ∆ {t}).card ≤ s.card + 1 := by rw [symmDiff_singleton_eq] split_ifs with h · exact (Finset.card_erase_le).trans (Nat.le_succ _) @@ -216,7 +217,7 @@ def addArg (p : Finset ℕ × Bool) (b : Bool) (a : Arg) : Finset ℕ × Bool := | .const v => (p.1, p.2 ^^ v) else p -theorem sum_addArg (p : Finset ℕ × Bool) (b : Bool) (a : Arg) (val : ℕ → Bool) : +private theorem sum_addArg (p : Finset ℕ × Bool) (b : Bool) (a : Arg) (val : ℕ → Bool) : ∑ i ∈ (addArg p b a).1, val i + (addArg p b a).2 = ∑ i ∈ p.1, val i + p.2 + (b && a.eval val) := by unfold addArg @@ -244,7 +245,7 @@ theorem mem_addArg {p : Finset ℕ × Bool} {b : Bool} {a : Arg} {z : ℕ} · exact Or.inl ((mem_symmDiff_singleton.1 h).2 hzt) | const v => exact Or.inl h -theorem card_addArg_le (p : Finset ℕ × Bool) (b : Bool) (a : Arg) : +private theorem card_addArg_le (p : Finset ℕ × Bool) (b : Bool) (a : Arg) : (addArg p b a).1.card ≤ p.1.card + 1 := by unfold addArg cases b diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Gate.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Gate.lean index 45e87f447..8c2cb0c93 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Gate.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Gate.lean @@ -222,7 +222,7 @@ theorem eval_subst {g : Gate} {v : ℕ} {ℓ : Lit} {val : ℕ → Bool} (h : va (g.subst v ℓ).eval val = g.eval val := by simp only [eval, subst, eval_substArg h] -theorem substArg_eq_node_of_ne {a : Arg} {v z : ℕ} {target : Arg} (hzv : z ≠ v) +private theorem substArg_eq_node_of_ne {a : Arg} {v z : ℕ} {target : Arg} (hzv : z ≠ v) (hzt : target ≠ .node z) : a.substArg v target = .node z ↔ a = .node z := by unfold Arg.substArg by_cases ha : a = .node v @@ -230,7 +230,7 @@ theorem substArg_eq_node_of_ne {a : Arg} {v z : ℕ} {target : Arg} (hzv : z ≠ exact ⟨fun h => absurd h hzt, fun h => absurd (Arg.node.inj h) (Ne.symm hzv)⟩ · rw [ite_eq_right ha] -theorem eq_node_of_substArg_eq_node {a : Arg} {v z : ℕ} {target : Arg} +private theorem eq_node_of_substArg_eq_node {a : Arg} {v z : ℕ} {target : Arg} (h : a.substArg v target = .node z) : a = .node z ∨ (a = .node v ∧ target = .node z) := by unfold Arg.substArg at h by_cases ha : a = .node v @@ -341,7 +341,7 @@ def Gate.Degenerate (g : Gate) : Prop := (∃ b, g.left = .const b) ∨ (∃ b, g.right = .const b) ∨ g.left = g.right /-- A Boolean function of one bit is a constant or a literal. -/ -theorem unary_cases (h : Bool → Bool) (x : Bool) : +private theorem unary_cases (h : Bool → Bool) (x : Bool) : h x = if h false = h true then h false else (x ^^ h false) := by cases x <;> cases h0 : h false <;> cases h1 : h true <;> simp_all @@ -430,7 +430,7 @@ instance (op : Bool → Bool → Bool) : Decidable (IsAffineOp op) := inferInstanceAs (Decidable (_ = _)) /-- An AND-type operation becomes constant when either argument takes a suitable value. -/ -theorem exists_eq_of_not_isAffineOp {op : Bool → Bool → Bool} (h : ¬ IsAffineOp op) : +private theorem exists_eq_of_not_isAffineOp {op : Bool → Bool → Bool} (h : ¬ IsAffineOp op) : (∃ b, op b false = op b true) ∧ (∃ b, op false b = op true b) := by unfold IsAffineOp at h constructor @@ -482,7 +482,7 @@ def IsUnaryOp (op : Bool → Bool → Bool) : Prop := /-- An operation that is not a projection or a negated projection is constant on a diagonal `{(c + a, a)}` for a suitable `c`, and likewise on `{(a, c + a)}`. -/ -theorem exists_diag_const (op : Bool → Bool → Bool) : +private theorem exists_diag_const (op : Bool → Bool → Bool) : ((∃ c, op c false = op (!c) true) ∧ (∃ c, op false c = op true (!c))) ∨ IsUnaryOp op := by by_cases h0 : op false false = op true true · exact Or.inl ⟨⟨false, h0⟩, ⟨false, h0⟩⟩ diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/OfCircuit.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/OfCircuit.lean index 105dcd32f..f2ecae4e1 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/OfCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/OfCircuit.lean @@ -69,7 +69,7 @@ theorem eval_lineGate {g : ℕ} (line : Line (fullSignature 2 Bool) n g) (val : · simp at ha · rfl -theorem reads_lineGate {g : ℕ} {line : Line (fullSignature 2 Bool) n g} {i : ℕ} +private theorem reads_lineGate {g : ℕ} {line : Line (fullSignature 2 Bool) n g} {i : ℕ} (h : (lineGate line).Reads i) : ∃ a, wireName (line.wires a) = i := by obtain ⟨op | c, w⟩ := line · rcases h with h | h @@ -101,7 +101,7 @@ def ofCircuit (C : Circuit (fullSignature 2 Bool) n 1) : SemiCircuit where @[simp] theorem ofCircuit_eqns (C : Circuit (fullSignature 2 Bool) n 1) : (ofCircuit C).eqns = ∅ := rfl -theorem ofCircuit_gate (C : Circuit (fullSignature 2 Bool) n 1) (k : Fin C.size) : +private theorem ofCircuit_gate (C : Circuit (fullSignature 2 Bool) n 1) (k : Fin C.size) : (ofCircuit C).gate (n + k) = lineGate (C.program.lines k) := by have h : n ≤ n + (k : ℕ) ∧ n + (k : ℕ) < n + C.size := ⟨Nat.le_add_right _ _, by omega⟩ simp only [ofCircuit, dite_eq_left h] diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Reparameterisation.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Reparameterisation.lean index c0cd5216e..b666c3c1b 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Reparameterisation.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Reparameterisation.lean @@ -61,7 +61,7 @@ theorem AffineIn.solve {Q x : ℕ} {c : Bool} {T : Finset ℕ} (h : C.AffineIn Q generalize val x = a; generalize ∑ j ∈ T.erase x, val j = b cases a <;> cases b <;> cases c <;> rfl -theorem params_union_aux_swap {x Q : ℕ} (hx : x ∈ C.params) (hQ : Q ∈ C.aux) : +private theorem params_union_aux_swap {x Q : ℕ} (hx : x ∈ C.params) (hQ : Q ∈ C.aux) : (C.swap x Q).params ∪ (C.swap x Q).aux = C.params ∪ C.aux := by ext i change i ∈ insert Q (C.params.erase x) ∪ insert x (C.aux.erase Q) ↔ _ @@ -71,7 +71,8 @@ theorem params_union_aux_swap {x Q : ℕ} (hx : x ∈ C.params) (hQ : Q ∈ C.au · subst hiQ; simp [hQ] · simp [hix, hiQ] -theorem live_swap {x Q : ℕ} (hx : x ∈ C.params) (hQ : Q ∈ C.aux) : (C.swap x Q).live = C.live := by +private theorem live_swap {x Q : ℕ} (hx : x ∈ C.params) (hQ : Q ∈ C.aux) : + (C.swap x Q).live = C.live := by change (C.swap x Q).params ∪ (C.swap x Q).aux ∪ C.gates = _ rw [params_union_aux_swap hx hQ] rfl @@ -182,18 +183,18 @@ namespace QuadOK variable {x y z G D : ℕ} {α β γ c : Bool} (h : C.QuadOK x y z G D α β γ c) include h -theorem notMem_terms_z {e : ℕ} (he : e ∈ C.eqns) : z ∉ (C.eqn e).terms := fun hz => by +private theorem notMem_terms_z {e : ℕ} (he : e ∈ C.eqns) : z ∉ (C.eqn e).terms := fun hz => by have : Sum.inr e ∈ C.children z := (inr_mem_children _).2 ⟨he, hz⟩ rw [h.children_z] at this simp at this -theorem not_reads_z {K : ℕ} (hK : K ∈ C.gates) (hKD : K ≠ D) : ¬ (C.gate K).Reads z := +private theorem not_reads_z {K : ℕ} (hK : K ∈ C.gates) (hKD : K ≠ D) : ¬ (C.gate K).Reads z := fun hr => by have : Sum.inl K ∈ C.children z := (inl_mem_children _).2 ⟨hK, hr⟩ rw [h.children_z] at this exact hKD (Sum.inl.inj (Finset.mem_singleton.1 this)) -theorem not_reads_G {K : ℕ} (hK : K ∈ C.gates) (hKD : K ≠ D) : ¬ (C.gate K).Reads G := +private theorem not_reads_G {K : ℕ} (hK : K ∈ C.gates) (hKD : K ≠ D) : ¬ (C.gate K).Reads G := fun hr => by have : Sum.inl K ∈ C.children G := (inl_mem_children _).2 ⟨hK, hr⟩ rw [h.children_G] at this diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Rewiring.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Rewiring.lean index b9d392361..714bc6993 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Rewiring.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Rewiring.lean @@ -91,7 +91,7 @@ theorem eqnsHold_iff (val : ℕ → Bool) : (C.moveAffine J e).EqnsHold val ↔ rwa [Function.update_self] · rw [h.eqn_of_mem he']; exact hv e' he' -theorem live_eq : (C.moveAffine J e).live = C.live := by +private theorem live_eq : (C.moveAffine J e).live = C.live := by ext i simp only [live, Finset.mem_union] change (i ∈ C.params ∨ i ∈ insert J C.aux) ∨ i ∈ C.gates.erase J ↔ _ @@ -233,10 +233,11 @@ structure RewireOK (C : SemiCircuit) (J : ℕ) (g : Gate) : Prop where value : ∀ val, (∀ K ∈ C.gates, K ≠ J → val K = (C.gate K).eval val) → g.eval val = (C.gate J).eval val -theorem rewire_gate_of_ne {J K : ℕ} {g : Gate} (hKJ : K ≠ J) : (C.rewire J g).gate K = C.gate K := +private theorem rewire_gate_of_ne {J K : ℕ} {g : Gate} (hKJ : K ≠ J) : + (C.rewire J g).gate K = C.gate K := Function.update_of_ne hKJ _ _ -theorem rewire_gate_self {J : ℕ} {g : Gate} : (C.rewire J g).gate J = g := +private theorem rewire_gate_self {J : ℕ} {g : Gate} : (C.rewire J g).gate J = g := Function.update_self _ _ _ /-- Rewiring a gate to read only parameters preserves well-formedness. -/ diff --git a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Simplification.lean b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Simplification.lean index ba206f2ab..bbd28c722 100644 --- a/Complexity/Computability/Circuit/Boolean/SemiCircuit/Simplification.lean +++ b/Complexity/Computability/Circuit/Boolean/SemiCircuit/Simplification.lean @@ -159,10 +159,11 @@ structure DeleteGateOK (C : SemiCircuit) (J : ℕ) (ℓ : Lit) : Prop where value : (∀ val, C.EqnsHold val → (C.gate J).eval val = ℓ.eval val) ∨ ((∀ K ∈ C.gates, ¬ (C.gate K).Reads J) ∧ ¬ C.out.Reads J) -theorem DeleteGateOK.not_reads (hC : C.WellFormed) {J : ℕ} {ℓ : Lit} (h : C.DeleteGateOK J ℓ) : +private theorem DeleteGateOK.not_reads (hC : C.WellFormed) {J : ℕ} {ℓ : Lit} + (h : C.DeleteGateOK J ℓ) : ℓ.arg ≠ .node J := fun he => hC.not_reads_self h.mem (h.reads J he) -theorem eqnsHold_deleteGate (hC : C.WellFormed) {J : ℕ} {ℓ : Lit} (hJ : J ∈ C.gates) +private theorem eqnsHold_deleteGate (hC : C.WellFormed) {J : ℕ} {ℓ : Lit} (hJ : J ∈ C.gates) (val : ℕ → Bool) : (C.deleteGate J ℓ).EqnsHold val ↔ C.EqnsHold val := forall₂_congr fun e he => by change ((C.eqn e).subst J ℓ).Holds val ↔ _ @@ -276,7 +277,7 @@ theorem mem_live_deleteEqn {e v : ℕ} {ℓ : Lit} {i : ℕ} (hi : i ∈ C.live) /-- A solution of the affine system after deleting `v = ℓ` extends to a solution of the original system by giving `v` the value of `ℓ`. -/ -theorem DeleteEqnOK.eqnsHold {e v : ℕ} {ℓ : Lit} (h : C.DeleteEqnOK e v ℓ) {val : ℕ → Bool} +private theorem DeleteEqnOK.eqnsHold {e v : ℕ} {ℓ : Lit} (h : C.DeleteEqnOK e v ℓ) {val : ℕ → Bool} (hval : (C.deleteEqn e v ℓ).EqnsHold val) : C.EqnsHold (Function.update val v (ℓ.eval val)) := by have hℓv : ℓ.arg ≠ .node v := fun he => (h.reads v he).2 rfl @@ -375,10 +376,10 @@ structure DropEqnOK (C : SemiCircuit) (e v : ℕ) : Prop where out : ¬ C.out.Reads v /-- The value of the dropped auxiliary variable solving its equation. -/ -def dropEqnValue (C : SemiCircuit) (e v : ℕ) (val : ℕ → Bool) : ℕ → Bool := +private def dropEqnValue (C : SemiCircuit) (e v : ℕ) (val : ℕ → Bool) : ℕ → Bool := Function.update val v ((C.eqn e).rhs + ∑ i ∈ (C.eqn e).terms.erase v, val i) -theorem DropEqnOK.eqnsHold {e v : ℕ} (h : C.DropEqnOK e v) {val : ℕ → Bool} +private theorem DropEqnOK.eqnsHold {e v : ℕ} (h : C.DropEqnOK e v) {val : ℕ → Bool} (hval : (C.dropEqn e v).EqnsHold val) : C.EqnsHold (C.dropEqnValue e v val) := by have hext : ∀ i, i ≠ v → C.dropEqnValue e v val i = val i := fun i hi => Function.update_of_ne hi _ _ @@ -451,7 +452,7 @@ def dropTrivialEqn (C : SemiCircuit) (e : ℕ) : SemiCircuit := /-- An equation without terms of a well-formed semi-circuit always holds, so dropping it keeps the solutions of the affine system. -/ -theorem eqnsHold_dropTrivialEqn (hC : C.WellFormed) {e : ℕ} (he : e ∈ C.eqns) +private theorem eqnsHold_dropTrivialEqn (hC : C.WellFormed) {e : ℕ} (he : e ∈ C.eqns) (hterms : (C.eqn e).terms = ∅) (val : ℕ → Bool) : (C.dropTrivialEqn e).EqnsHold val ↔ C.EqnsHold val := by have htriv : (C.eqn e).Holds val := by diff --git a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Bounds.lean b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Bounds.lean index 54318592d..8a497626b 100644 --- a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Bounds.lean +++ b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Bounds.lean @@ -38,7 +38,7 @@ namespace Cslib.Circuits.Boolean.ShallowSymmetric open Finset /-- Products of numbers below `2 ^ (a k)` and `2 ^ (b k)` are below `2 ^ ((a + b) k)`. -/ -theorem mul_le_two_pow_add_mul {k a b x y : ℕ} (hx : x ≤ 2 ^ (a * k)) +private theorem mul_le_two_pow_add_mul {k a b x y : ℕ} (hx : x ≤ 2 ^ (a * k)) (hy : y ≤ 2 ^ (b * k)) : x * y ≤ 2 ^ ((a + b) * k) := by calc x * y ≤ 2 ^ (a * k) * 2 ^ (b * k) := Nat.mul_le_mul hx hy @@ -57,7 +57,7 @@ theorem add_le_two_pow_add_add_one_mul {k a b x y : ℕ} (hk : 1 ≤ k) (hx : x _ ≤ _ := Nat.pow_le_pow_right (by omega) (by nlinarith) /-- A constant `c` is below `2 ^ (c k)` for `k ≥ 1`. -/ -theorem le_two_pow_mul (c k : ℕ) (hk : 1 ≤ k) : c ≤ 2 ^ (c * k) := +private theorem le_two_pow_mul (c k : ℕ) (hk : 1 ≤ k) : c ≤ 2 ^ (c * k) := Nat.lt_two_pow_self.le.trans (Nat.pow_le_pow_right (by omega) (by nlinarith)) diff --git a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Construction.lean b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Construction.lean index 1469d732d..436141320 100644 --- a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Construction.lean +++ b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Construction.lean @@ -100,7 +100,7 @@ open Finset /-- Synthesize a simultaneous modular test without increasing the comparison depth. The bound counts all ordered pairs, including harmless diagonal pairs. -/ -theorem exists_test_altFormula {n d B M : ℕ} {ι : Type*} [Fintype ι] +private theorem exists_test_altFormula {n d B M : ℕ} {ι : Type*} [Fintype ι] (k : ι → ℕ) [∀ i, NeZero (k i)] (ih : ∀ m ≤ M, ∀ a : ℕ → Bool, ∃ f : AltFormula m (d + 2), AltFormula.size f ≤ B ∧ diff --git a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Covering.lean b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Covering.lean index ee457d38e..21a48f19e 100644 --- a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Covering.lean +++ b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/Covering.lean @@ -39,7 +39,7 @@ as in the paper. The resulting density `k! / k^k` still gives the required expon namespace Cslib.Circuits.Boolean.ShallowSymmetric /-- A convenient elementary form of the factorial estimate; no asymptotics. -/ -theorem pow_self_le_three_pow_mul_factorial (k : ℕ) : +private theorem pow_self_le_three_pow_mul_factorial (k : ℕ) : k ^ k ≤ 3 ^ k * k.factorial := by have h := Real.pow_div_factorial_le_exp (x := (k : ℝ)) (by positivity) k have he : Real.exp (k : ℝ) ≤ (3 : ℝ) ^ k := by diff --git a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/ShiftTest.lean b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/ShiftTest.lean index 602a693f5..0a5173c45 100644 --- a/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/ShiftTest.lean +++ b/Complexity/Computability/Circuit/Boolean/ShallowSymmetric/ShiftTest.lean @@ -70,7 +70,7 @@ theorem ShiftTest.sound {t : G} {w s : G → G} (h : ShiftTest t w s) : exact add_right_cancel (b := residueSum G - t) (by simpa using hs) /-- For a valid weight vector, choosing a permutation determines the shifts. -/ -theorem shiftTest_perm {t : G} (w : G → G) (hw : ∑ i, w i = t) +private theorem shiftTest_perm {t : G} (w : G → G) (hw : ∑ i, w i = t) (e : Equiv.Perm G) : ShiftTest t w (fun i => e i - w i) := by constructor · rw [sum_sub_distrib, hw] @@ -79,7 +79,7 @@ theorem shiftTest_perm {t : G} (w : G → G) (hw : ∑ i, w i = t) · simpa only [add_sub_cancel] using e.injective /-- Accepting shifts are precisely permutations translated by the weight vector. -/ -noncomputable def acceptingShiftsEquiv {t : G} (w : G → G) (hw : ∑ i, w i = t) : +private noncomputable def acceptingShiftsEquiv {t : G} (w : G → G) (hw : ∑ i, w i = t) : {s : G → G // ShiftTest t w s} ≃ Equiv.Perm G where toFun s := Equiv.ofBijective (fun i => w i + s.1 i) (Finite.injective_iff_bijective.mp s.2.2) diff --git a/Complexity/Computability/Circuit/Boolean/Smolensky/Approximation.lean b/Complexity/Computability/Circuit/Boolean/Smolensky/Approximation.lean index 655ad8706..0d5207a0e 100644 --- a/Complexity/Computability/Circuit/Boolean/Smolensky/Approximation.lean +++ b/Complexity/Computability/Circuit/Boolean/Smolensky/Approximation.lean @@ -70,7 +70,7 @@ noncomputable def gateApprox (hℓ : 1 ≤ ℓ) (op : Unbounded.extSignature.Op) Classical.choose (exists_gate_approx (R := R) (p := p) hℓ op u) variable (R p) in -theorem gateApprox_spec (hℓ : 1 ≤ ℓ) (op : Unbounded.extSignature.Op) +private theorem gateApprox_spec (hℓ : 1 ≤ ℓ) (op : Unbounded.extSignature.Op) (u : BitString n → Fin (Unbounded.extSignature.Arity op) → Bool) : (∀ (D : ℕ) (v : Fin (Unbounded.extSignature.Arity op) → BitString n → R), (∀ k, v k ∈ lowDegree R (Fin n) D) → @@ -90,7 +90,7 @@ noncomputable def pairInterpretation (hℓ : 1 ≤ ℓ) : variable {g : ℕ} (hℓ : 1 ≤ ℓ) (P : Program Unbounded.extSignature n g) /-- The true functions of the pair evaluation are the gate functions of the program. -/ -theorem fst_trace_pair (w : Wire n g) (x : BitString n) : +private theorem fst_trace_pair (w : Wire n g) (x : BitString n) : (P.trace (pairInterpretation R p hℓ) inputPair w).1 x = P.trace (Unbounded.extInterpretation (modGate p)) x w := by -- the first components form a homomorphism to the pointwise lift, then evaluate at `x` @@ -101,7 +101,7 @@ theorem fst_trace_pair (w : Wire n g) (x : BitString n) : (P.trace_pointwise_apply _ _ w x) /-- The pair at a gate is its operation applied to the pairs at its wires. -/ -theorem trace_pair_gate (k : Fin g) : +private theorem trace_pair_gate (k : Fin g) : P.trace (pairInterpretation R p hℓ) inputPair (.gate k) = pairInterpretation R p hℓ (P.lines k).op fun a => P.trace (pairInterpretation R p hℓ) inputPair ((P.lines k).wires a) := @@ -136,11 +136,11 @@ noncomputable def errorSet (k : Fin g) : Finset (BitString n) := bitVal R (Unbounded.extInterpretation (modGate p) (P.lines k).op (fun a => (P.trace (pairInterpretation R p hℓ) inputPair ((P.lines k).wires a)).1 x)) -theorem card_errorSet_mul_le (k : Fin g) : #(errorSet R p hℓ P k) * 2 ^ ℓ ≤ 2 ^ n := +private theorem card_errorSet_mul_le (k : Fin g) : #(errorSet R p hℓ P k) * 2 ^ ℓ ≤ 2 ^ n := (gateApprox_spec R p hℓ (P.lines k).op _).2 /-- **Exactness of the approximants** where no gate approximator errs. -/ -theorem snd_trace_pair_eq {x : BitString n} (hx : ∀ k, x ∉ errorSet R p hℓ P k) +private theorem snd_trace_pair_eq {x : BitString n} (hx : ∀ k, x ∉ errorSet R p hℓ P k) (w : Wire n g) : (P.trace (pairInterpretation R p hℓ) inputPair w).2 x = bitVal R ((P.trace (pairInterpretation R p hℓ) inputPair w).1 x) := by diff --git a/Complexity/Computability/Circuit/Boolean/Smolensky/Gates.lean b/Complexity/Computability/Circuit/Boolean/Smolensky/Gates.lean index 8c936751a..7ba63c432 100644 --- a/Complexity/Computability/Circuit/Boolean/Smolensky/Gates.lean +++ b/Complexity/Computability/Circuit/Boolean/Smolensky/Gates.lean @@ -127,13 +127,14 @@ end Approximators /-! ### Sums of bits -/ /-- A sum of bits is their count. -/ -theorem sum_bitVal (S : Finset (Fin m)) (u : Fin m → Bool) : +private theorem sum_bitVal (S : Finset (Fin m)) (u : Fin m → Bool) : ∑ i ∈ S, bitVal R (u i) = (#(S.filter fun i => u i = true) : R) := by rw [Finset.card_filter, Nat.cast_sum] exact Finset.sum_congr rfl fun i _ => by cases u i <;> simp [bitVal] /-- If some coordinate is true, at most half of the sets have a sum of bits equal to zero. -/ -theorem two_mul_card_sum_eq_zero_le [Nontrivial R] [DecidableEq R] (u : Fin m → Bool) {k : Fin m} +private theorem two_mul_card_sum_eq_zero_le [Nontrivial R] [DecidableEq R] (u : Fin m → Bool) + {k : Fin m} (hk : u k = true) : 2 * #(univ.filter fun S : Finset (Fin m) => ∑ i ∈ S, bitVal R (u i) = 0) ≤ 2 ^ m := by set Z := univ.filter fun S : Finset (Fin m) => ∑ i ∈ S, bitVal R (u i) = 0 @@ -159,7 +160,7 @@ theorem two_mul_card_sum_eq_zero_le [Nontrivial R] [DecidableEq R] (u : Fin m variable {p : ℕ} [Fact p.Prime] -theorem orApprox_bitVal_of_forall_false (T : Fin ℓ → Finset (Fin m)) (u : Fin m → Bool) +private theorem orApprox_bitVal_of_forall_false (T : Fin ℓ → Finset (Fin m)) (u : Fin m → Bool) (hu : ∀ i, u i = false) : orApprox p T (fun i => bitVal R (u i)) = 0 := by have hp := (Fact.out : p.Prime).two_le simp [orApprox, hu, bitVal, zero_pow (show p - 1 ≠ 0 by omega)] @@ -181,17 +182,17 @@ theorem natCast_pow_eq_bitVal (c : ℕ) : simp [h, hc, bitVal] /-- In characteristic `p`, the `(p - 1)`-st power of a nonzero count is `1`. -/ -theorem natCast_pow_eq_one {c : ℕ} (hc : (c : R) ≠ 0) : (c : R) ^ (p - 1) = 1 := by +private theorem natCast_pow_eq_one {c : ℕ} (hc : (c : R) ≠ 0) : (c : R) ^ (p - 1) = 1 := by have h : c % p ≠ 0 := fun h => hc ((CharP.cast_eq_zero_iff R p c).2 (Nat.dvd_of_mod_eq_zero h)) simp [natCast_pow_eq_bitVal, h, bitVal] /-- The `MOD_p` polynomial is exact on bits. -/ -theorem modApprox_bitVal (u : Fin m → Bool) : +private theorem modApprox_bitVal (u : Fin m → Bool) : modApprox p (fun i => bitVal R (u i)) = bitVal R (modGate p m u) := by rw [modApprox, sum_bitVal, natCast_pow_eq_bitVal] rfl -theorem orApprox_bitVal_of_exists (T : Fin ℓ → Finset (Fin m)) (u : Fin m → Bool) +private theorem orApprox_bitVal_of_exists (T : Fin ℓ → Finset (Fin m)) (u : Fin m → Bool) (hT : ∃ j, ∑ i ∈ T j, bitVal R (u i) ≠ 0) : orApprox p T (fun i => bitVal R (u i)) = 1 := by obtain ⟨j, hj⟩ := hT @@ -239,7 +240,7 @@ theorem card_orApprox_wrong_mul_le (u : Fin m → Bool) : /-- **Averaging over the inputs.** For arguments `u x` depending on the input, some tuple makes the OR approximator err on at most `2 ^ n / 2 ^ ℓ` inputs. -/ -theorem exists_orApprox (u : BitString n → Fin m → Bool) : +private theorem exists_orApprox (u : BitString n → Fin m → Bool) : ∃ T : Fin ℓ → Finset (Fin m), #(univ.filter fun x => orApprox p T (fun i => bitVal R (u x i)) ≠ bitVal R (decide (∃ j, u x j = true))) * 2 ^ ℓ ≤ 2 ^ n := by diff --git a/Complexity/Computability/Circuit/Boolean/Sorting.lean b/Complexity/Computability/Circuit/Boolean/Sorting.lean index 4961c3ac8..47b9e75d3 100644 --- a/Complexity/Computability/Circuit/Boolean/Sorting.lean +++ b/Complexity/Computability/Circuit/Boolean/Sorting.lean @@ -83,7 +83,8 @@ end bitonicLayerCircuit open bitonicLayerCircuit /-- Gather reads corresponding records from the two halves without changing their bits. -/ -theorem bitonicLayerCircuit.gather_pair {n r : ℕ} (x : BitString ((n + n) * r)) (j : Fin n) : +private theorem bitonicLayerCircuit.gather_pair {n r : ℕ} (x : BitString ((n + n) * r)) + (j : Fin n) : directProductInput (x ∘ gather n r) j = Fin.append (directProductInput x (Fin.castAdd n j)) (directProductInput x (Fin.natAdd n j)) := by @@ -108,13 +109,13 @@ end bitonicMergeCircuit open bitonicMergeCircuit /-- The first flat input block is the first half of the record array. -/ -theorem bitonicMergeCircuit.records_firstHalf {n r : ℕ} (x : BitString ((n + n) * r)) : +private theorem bitonicMergeCircuit.records_firstHalf {n r : ℕ} (x : BitString ((n + n) * r)) : directProductInput (x ∘ firstHalf n r) = directProductInput x ∘ Fin.castAdd n := by funext j b simp only [firstHalf, directProductInput, Function.comp_apply, Equiv.symm_apply_apply] /-- The second flat input block is the second half of the record array. -/ -theorem bitonicMergeCircuit.records_secondHalf {n r : ℕ} (x : BitString ((n + n) * r)) : +private theorem bitonicMergeCircuit.records_secondHalf {n r : ℕ} (x : BitString ((n + n) * r)) : directProductInput (x ∘ secondHalf n r) = directProductInput x ∘ Fin.natAdd n := by funext j b simp only [secondHalf, directProductInput, Function.comp_apply, Equiv.symm_apply_apply] @@ -300,7 +301,7 @@ private theorem eval_chain {input a b n m r : ℕ} def pairs {n : ℕ} (flags : BitString n) : Fin n → BitString 2 := fun i => ![flags i, !flags i] -theorem pairs_append {n m : ℕ} (x : BitString n) (y : BitString m) : +private theorem pairs_append {n m : ℕ} (x : BitString n) (y : BitString m) : pairs (Fin.append x y) = Fin.append (pairs x) (pairs y) := by funext i b cases i using Fin.addCases <;> simp only [pairs, Fin.append_left, Fin.append_right] @@ -510,7 +511,7 @@ theorem eval_bitonicSortTraceCircuit {k r : ℕ} (key : Fin k → Fin r) (d : erw [controls_pack, records_pack, ← pairs_append, ← pairs_append] /-- A traced merge computes each comparator once, retaining its existing control pair. -/ -theorem cost_program_bitonicMergeTraceCircuit {k r : ℕ} (key : Fin k → Fin r) (d : ℕ) +private theorem cost_program_bitonicMergeTraceCircuit {k r : ℕ} (key : Fin k → Fin r) (d : ℕ) (ascending : Bool) (cost : signature.Op → ℕ) : (bitonicMergeTraceCircuit key d ascending).program.cost cost = mergeTraceSize d * (compareSwapCircuit.record @@ -625,7 +626,7 @@ theorem bitonicSortCircuit_perm {k r : ℕ} (key : Fin k → Fin r) (depth : ℕ exact BitonicSort.sort_perm _ _ _ _ /-- A layer uses `n` copies of the comparator under any assignment of gate costs. -/ -theorem cost_program_bitonicLayerCircuit {k r : ℕ} (key : Fin k → Fin r) (n : ℕ) +private theorem cost_program_bitonicLayerCircuit {k r : ℕ} (key : Fin k → Fin r) (n : ℕ) (ascending : Bool) (cost : signature.Op → ℕ) : (bitonicLayerCircuit key n ascending).program.cost cost = n * (compareSwapCircuit key).program.cost cost := by diff --git a/Complexity/Computability/Circuit/Boolean/SortingTrace.lean b/Complexity/Computability/Circuit/Boolean/SortingTrace.lean index b3499ce82..897a997a4 100644 --- a/Complexity/Computability/Circuit/Boolean/SortingTrace.lean +++ b/Complexity/Computability/Circuit/Boolean/SortingTrace.lean @@ -180,7 +180,7 @@ private theorem cost_unchain {a b n r : ℕ} (first : Circuit signature (a * 2 + Circuit.cost_program_wiringOn, Nat.zero_add] exact Nat.add_comm _ _ -theorem pairs_comp {a b : ℕ} (flags : BitString a) (f : Fin b → Fin a) : +private theorem pairs_comp {a b : ℕ} (flags : BitString a) (f : Fin b → Fin a) : pairs (flags ∘ f) = pairs flags ∘ f := rfl end bitonicSortTraceCircuit @@ -236,7 +236,7 @@ theorem eval_bitonicUnsortCircuit (r d : ℕ) (flags : BitString (sortTraceSize simp only [← pairs_comp, ih] /-- A reverse merge charges only switching; saved controls require no new negations. -/ -theorem cost_program_bitonicUnmergeCircuit (r d : ℕ) (cost : signature.Op → ℕ) : +private theorem cost_program_bitonicUnmergeCircuit (r d : ℕ) (cost : signature.Op → ℕ) : (bitonicUnmergeCircuit r d).program.cost cost = mergeTraceSize d * (2 * r * (2 * cost .and + cost .or)) := by induction d with diff --git a/Complexity/Computability/Circuit/Boolean/Substitution.lean b/Complexity/Computability/Circuit/Boolean/Substitution.lean index bcab6cae3..473cefc51 100644 --- a/Complexity/Computability/Circuit/Boolean/Substitution.lean +++ b/Complexity/Computability/Circuit/Boolean/Substitution.lean @@ -112,7 +112,7 @@ theorem depth_substituteCircuit_le {n N : ℕ} (ρ : Fin N → Fin n ⊕ Bool) : (Formula.depth_toCircuit_le _).trans (by simp [Formula.const]) /-- A substitution costs at most two gates, one for each constant. -/ -theorem complexity_substitute_le_two (ρ : Fin N → Fin n ⊕ Bool) : +private theorem complexity_substitute_le_two (ρ : Fin N → Fin n ⊕ Bool) : complexity interpretation (substitute ρ) ≤ 2 := by simpa only [size_substituteCircuit] using complexity_le_of_computes (substituteCircuit ρ) (eval_substituteCircuit ρ) diff --git a/Complexity/Computability/Circuit/Boolean/Synthesis.lean b/Complexity/Computability/Circuit/Boolean/Synthesis.lean index d892829e4..aa391b155 100644 --- a/Complexity/Computability/Circuit/Boolean/Synthesis.lean +++ b/Complexity/Computability/Circuit/Boolean/Synthesis.lean @@ -195,7 +195,7 @@ theorem complexity_not_le (f : BooleanFunction n) : /-- Combining two outputs with a binary operation that costs `c` gates on two inputs costs `c` gates. -/ -theorem complexity_binary_le (f g : BooleanFunction n) (op : Bool → Bool → Bool) {c : ℕ} +private theorem complexity_binary_le (f g : BooleanFunction n) (op : Bool → Bool → Bool) {c : ℕ} (hop : Synthesis interpretation (inputs 2) {fun y : Fin 2 → Bool => op (y 0) (y 1)} c) : complexity interpretation (single fun x => op (f x) (g x)) ≤ complexity interpretation (single f) + complexity interpretation (single g) + c := diff --git a/Complexity/Computability/Circuit/Boolean/Tableau/Correct.lean b/Complexity/Computability/Circuit/Boolean/Tableau/Correct.lean index ad70a212b..f239b899b 100644 --- a/Complexity/Computability/Circuit/Boolean/Tableau/Correct.lean +++ b/Complexity/Computability/Circuit/Boolean/Tableau/Correct.lean @@ -61,7 +61,7 @@ variable {k : ℕ} {State : Type} [Fintype State] [DecidableEq State] /-! ### Values of wires -/ /-- The value of a De Morgan gate from its operation and its first two arguments. -/ -def opVal : Op → Bool → Bool → Bool +private def opVal : Op → Bool → Bool → Bool | .const b, _, _ => b | .not, a, _ => !a | .and, a, b => a && b @@ -78,7 +78,7 @@ noncomputable def val (T : ℕ) (x : List Bool) (w : ℕ) : Bool := variable {T : ℕ} {x : List Bool} /-- The value of a numbered gate is its operation applied to the values of its arguments. -/ -theorem val_add {g : ℕ} (hg : g < numGates k State T) : +private theorem val_add {g : ℕ} (hg : g < numGates k State T) : val tm T x (x.length + g) = interpretation (gateCode tm x.length T g).1 fun a => (gateCode tm x.length T g).2[a.val]?.elim false (val tm T x) := by exact getD_evalCode interpretation false x (isCodeFrom_gates tm x.length T) @@ -153,7 +153,8 @@ def gfSem {input : List Bool} (cfg : Cfg k Bool State input) : GFeat State → B /-- Whether the action of the step from a configuration has the attribute `v`: never, once halted. -/ -noncomputable def actSem {input : List Bool} (cfg : Cfg k Bool State input) (v : Attr k State) : +private noncomputable def actSem {input : List Bool} (cfg : Cfg k Bool State input) + (v : Attr k State) : Bool := match cfg.state with | none => false @@ -168,7 +169,7 @@ def Invariant (t : ℕ) : Prop := colSem T (tm.runFrom (tm.initCfg x) t) c f /-- The first block holds the initial configuration. -/ -theorem invariant_zero : Invariant tm T x 0 := by +private theorem invariant_zero : Invariant tm T x 0 := by refine ⟨fun f => ?_, fun c hc f => ?_⟩ · rw [val_wire tm (l := .gf f true 7) rfl (Nat.zero_le _)] rcases f with q | o <;> simp [initBit, gfInit, gfSem, runFrom, Cfg.init, eq_comm] @@ -212,7 +213,7 @@ private theorem val_resolve_node {t c : ℕ} {p : Bool} {l : Loc k State} {cs : variable (T x) in /-- The contribution of column `c` to a scanned quantity. -/ -def termSem (cfg : Cfg k Bool State x) (c : ℕ) : ScanQ k → Prop +private def termSem (cfg : Cfg k Bool State x) (c : ℕ) : ScanQ k → Prop | .inRead s => cfg.inputPos.val = c ∧ inputAt x c = s | .read i s => cfg.workTapePos i = (c : ℤ) - T ∧ cfg.workTapes i ((c : ℤ) - T) = s @@ -227,7 +228,7 @@ private theorem inputAt_eq_some {c : ℕ} (h : 1 ≤ c ∧ c ≤ x.length) : variable (x) in /-- The symbol read by a head of a configuration. -/ -def readSem (cfg : Cfg k Bool State x) : ScanQ k → Prop +private def readSem (cfg : Cfg k Bool State x) : ScanQ k → Prop | .inRead s => cfg.inputSymbol = s | .read i s => cfg.workTapeSymbols i = s @@ -242,7 +243,7 @@ private theorem sitOf_equivFin (y : Situation k State) : variable (T x) in /-- The value of a term of a feature, from block `t` and column `c`: both of its wires are true. -/ -noncomputable def termVal (t c : ℕ) (p : Ref k State × Ref k State) : Bool := +private noncomputable def termVal (t c : ℕ) (p : Ref k State × Ref k State) : Bool := val tm T x (p.1.resolve x.length T t c) && val tm T x (p.2.resolve x.length T t c) section Step @@ -713,7 +714,7 @@ private theorem val_col_step {c : ℕ} (hc : c < numCols T) (f : ColFeat k) : · simp [hz, Ne.symm hz] /-- One step of the simulation: the invariant passes from block `t` to block `t + 1`. -/ -theorem invariant_succ : Invariant tm T x (t + 1) := +private theorem invariant_succ : Invariant tm T x (t + 1) := ⟨fun f => val_gf_step tm hinv hn htT f, fun _ hc f => val_col_step tm hinv hn htT hc f⟩ end Step diff --git a/Complexity/Computability/Circuit/Boolean/Threshold/Parity.lean b/Complexity/Computability/Circuit/Boolean/Threshold/Parity.lean index 72aac9214..5bb00eab7 100644 --- a/Complexity/Computability/Circuit/Boolean/Threshold/Parity.lean +++ b/Complexity/Computability/Circuit/Boolean/Threshold/Parity.lean @@ -66,7 +66,7 @@ def negIf : Bool → Circuit signature 1 1 · simp [negIf, Subsingleton.elim o 0] · simp [negIf] -theorem cost_program_negIf (b : Bool) : (negIf b).program.cost thresholdCost = 0 := by +private theorem cost_program_negIf (b : Bool) : (negIf b).program.cost thresholdCost = 0 := by cases b <;> rfl @[simp] theorem size_negIf (b : Bool) : (negIf b).size = b.toNat := by diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold.lean index f64e182b0..6dc11de54 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold.lean @@ -104,7 +104,7 @@ def lineWeight (line : Line signature n g) (wire : Wire n g) : ℝ := ∑ a with line.wires a = wire, line.op.weight a /-- Regrouping argument slots by actual wire preserves their weighted sum. -/ -theorem sum_lineWeight_mul (line : Line signature n g) (values : Wire n g → ℝ) : +private theorem sum_lineWeight_mul (line : Line signature n g) (values : Wire n g → ℝ) : ∑ a, line.op.weight a * values (line.wires a) = ∑ wire, lineWeight line wire * values wire := by rw [← sum_fiberwise univ line.wires (fun a => line.op.weight a * values (line.wires a))] diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activation.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activation.lean index 442cb80f5..a2b9547d9 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activation.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activation.lean @@ -97,7 +97,7 @@ def activationLineWeight (line : Line activationSignature n g) (wire : Wire n g) ∑ a with line.wires a = wire, line.op.weight a /-- Regrouping argument slots by actual wire preserves their weighted sum. -/ -theorem sum_activationLineWeight_mul (line : Line activationSignature n g) +private theorem sum_activationLineWeight_mul (line : Line activationSignature n g) (values : Wire n g → ℝ) : ∑ a, line.op.weight a * values (line.wires a) = ∑ wire, activationLineWeight line wire * values wire := by @@ -143,7 +143,7 @@ theorem eval_activationGate_eq (p : Program activationSignature n g) rfl /-- A gate has zero coefficient on its own output and on later gate outputs. -/ -theorem activationGateWeight_eq_zero_of_le (p : Program activationSignature n g) +private theorem activationGateWeight_eq_zero_of_le (p : Program activationSignature n g) (gate prior : Fin g) (h : gate ≤ prior) : activationGateWeight p gate prior = 0 := by unfold activationGateWeight activationLineWeight apply sum_eq_zero diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activity.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activity.lean index 66fdf31ad..5822f20b7 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activity.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Activity.lean @@ -175,7 +175,7 @@ theorem card_attainableTranscripts_le_sum_choose_gateActivity (p : Program signa /-- Every realized transcript lies in the Hamming ball of radius `e` around any fixed baseline `v` whenever `inputActivityFrom p v ≤ e`. -/ -theorem card_attainableTranscripts_le_sum_choose_of_inputActivityFrom_le +private theorem card_attainableTranscripts_le_sum_choose_of_inputActivityFrom_le (p : Program signature n g) (v : inputGates p → Bool) {e : ℕ} (he : inputActivityFrom p v ≤ e) : (attainableTranscripts p).card ≤ diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/CapacityCircuit.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/CapacityCircuit.lean index 5cb51d481..71f6f971a 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/CapacityCircuit.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/CapacityCircuit.lean @@ -206,7 +206,7 @@ noncomputable def evalFrom (p : Program signature n g) (fixed : Finset (Fin g)) gateWeight p gate prior * (evalFrom p fixed η z prior).toNat else 0) termination_by gate -theorem evalFrom_eq (p : Program signature n g) (fixed : Finset (Fin g)) (η : Fin g → Bool) +private theorem evalFrom_eq (p : Program signature n g) (fixed : Finset (Fin g)) (η : Fin g → Bool) (z : Fin g → ℝ) (gate : Fin g) : evalFrom p fixed η z gate = if gate ∈ fixed then η gate else decide ((p.lines gate).op.threshold ≤ z gate + @@ -505,7 +505,7 @@ def singleRun (p : Program signature n g) (w : Fin n → ℝ) along := along /-- The slope of a gate of run `i` along the direction of the run, and zero elsewhere. -/ -noncomputable def DirectionRuns.slope {p : Program signature n g} {B : ℕ} +private noncomputable def DirectionRuns.slope {p : Program signature n g} {B : ℕ} (R : DirectionRuns p B) (i : ℕ) (gate : Fin g) : ℝ := open scoped Classical in if R.run gate = i ∧ gate ∈ inputGates p then (R.along gate).choose else 0 @@ -577,7 +577,7 @@ noncomputable def DirectionRuns.toBlockDecomposition (p : Program signature n g) funext gate simp [R.run_lt gate] -theorem DirectionRuns.cost_toBlockDecomposition (p : Program signature n g) +private theorem DirectionRuns.cost_toBlockDecomposition (p : Program signature n g) (readout : (Fin g → Bool) → Bool) {B : ℕ} (R : DirectionRuns p B) : (R.toBlockDecomposition p readout).cost = ∏ i ∈ Finset.range B, (BlockKind.oneDim (2 ^ R.size i - 1)).cost := @@ -593,7 +593,7 @@ private theorem two_pow_succ_le (r : ℕ) : 2 ^ (r + 1) ≤ 4 ^ r + 1 := by rw [pow_succ 2 (r + 1), pow_succ 4 r] omega -theorem cost_oneDim_le_four_pow (r : ℕ) : (BlockKind.oneDim (2 ^ r - 1)).cost ≤ 4 ^ r := by +private theorem cost_oneDim_le_four_pow (r : ℕ) : (BlockKind.oneDim (2 ^ r - 1)).cost ≤ 4 ^ r := by rcases r with _ | r · simp [BlockKind.cost] · have h1 : 1 < 2 ^ (r + 1) := Nat.one_lt_two_pow (by omega) @@ -603,7 +603,8 @@ theorem cost_oneDim_le_four_pow (r : ℕ) : (BlockKind.oneDim (2 ^ r - 1)).cost rw [pow_succ 4 r] omega -theorem cost_oneDim_le_four_mul (r : ℕ) : (BlockKind.oneDim (2 ^ r - 1)).cost ≤ 4 * 2 ^ r := by +private theorem cost_oneDim_le_four_mul (r : ℕ) : + (BlockKind.oneDim (2 ^ r - 1)).cost ≤ 4 * 2 ^ r := by have := Nat.one_le_two_pow (n := r) simp only [BlockKind.cost] split_ifs <;> omega @@ -623,7 +624,7 @@ theorem DirectionRuns.prod_cost_le_four_pow {p : Program signature n g} {B : ℕ Finset.prod_le_prod fun i _ => cost_oneDim_le_four_pow _ _ = 4 ^ (inputGates p).card := by rw [Finset.prod_pow_eq_pow_sum, R.sum_size] -theorem DirectionRuns.prod_cost_le_four_pow_mul {p : Program signature n g} {B : ℕ} +private theorem DirectionRuns.prod_cost_le_four_pow_mul {p : Program signature n g} {B : ℕ} (R : DirectionRuns p B) : ∏ i ∈ Finset.range B, (BlockKind.oneDim (2 ^ R.size i - 1)).cost ≤ 4 ^ B * 2 ^ (inputGates p).card := by @@ -649,7 +650,7 @@ private theorem lt_of_two_pow_lt_mul {n k K X e : ℕ} (hK : K ≤ 2 ^ k) (hX : consecutive runs along single directions, with `rᵢ` input-reading gates in run `i`. Then `2 ^ n < 4 * K ^ 2 * ∏ i, cᵢ`, where `cᵢ = 4 * (2 ^ rᵢ - 1)` if `rᵢ ≥ 1` and `cᵢ = 1` otherwise. -/ -theorem two_pow_lt_of_directionRuns (p : Program signature n g) +private theorem two_pow_lt_of_directionRuns (p : Program signature n g) (readout : (Fin g → Bool) → Bool) {B : ℕ} (R : DirectionRuns p B) {f : Cslib.BooleanFunction n} {K : ℕ} (hreadout : ∀ x, readout (p.eval interpretation x) = f x) diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Components.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Components.lean index a25058aee..f79e6534c 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Components.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Components.lean @@ -131,7 +131,7 @@ theorem sum_card_componentInputs : ∑ c, (componentInputs p c).card = n := by simpa [componentInputs] using h.symm open Classical in -theorem pairwiseDisjoint_componentInputs : +private theorem pairwiseDisjoint_componentInputs : ((univ : Finset (supportGraph p).ConnectedComponent) : Set _).PairwiseDisjoint (componentInputs p) := by intro c _ c' _ hcc' @@ -141,7 +141,7 @@ theorem pairwiseDisjoint_componentInputs : exact hcc' (hu.symm.trans hu') open Classical in -theorem pairwiseDisjoint_componentGates : +private theorem pairwiseDisjoint_componentGates : ((univ : Finset (supportGraph p).ConnectedComponent) : Set _).PairwiseDisjoint (componentGates p) := by intro c _ c' _ hcc' @@ -155,7 +155,7 @@ theorem pairwiseDisjoint_componentGates : open Classical in /-- The input-reading gates are partitioned by the connected components of `supportGraph p`. -/ -theorem inputGates_eq_biUnion_componentGates : +private theorem inputGates_eq_biUnion_componentGates : inputGates p = univ.biUnion (componentGates p) := by ext j simp only [mem_biUnion, mem_univ, true_and, mem_componentGates, ← inputSupport_ne_empty_iff] @@ -421,7 +421,7 @@ theorem residualGates_subset_inputGates (p : Program signature n g) (F b : Finse rw [← inputSupport_ne_empty_iff] exact fun h0 => hj.1 (h0 ▸ empty_subset F) -theorem disjoint_residualGates (p : Program signature n g) (F : Finset (Fin n)) +private theorem disjoint_residualGates (p : Program signature n g) (F : Finset (Fin n)) {b b' : Finset (Fin n)} (hbb' : Disjoint b b') : Disjoint (residualGates p F b) (residualGates p F b') := by rw [disjoint_left] @@ -434,7 +434,7 @@ theorem disjoint_residualGates (p : Program signature n g) (F : Finset (Fin n)) /-- Over pairwise disjoint blocks `𝓑`, the total number of residual gates is at most `(inputGates p).card`. -/ -theorem sum_card_residualGates_le (p : Program signature n g) (F : Finset (Fin n)) +private theorem sum_card_residualGates_le (p : Program signature n g) (F : Finset (Fin n)) (𝓑 : Finset (Finset (Fin n))) (hdisj : (𝓑 : Set (Finset (Fin n))).PairwiseDisjoint id) : ∑ b ∈ 𝓑, (residualGates p F b).card ≤ (inputGates p).card := by classical diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Cut.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Cut.lean index 872f41576..d1f65b4da 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Cut.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Cut.lean @@ -125,7 +125,7 @@ theorem card_lt_or_card_lt_of_rectangleFree {f : Cslib.BooleanFunction n} {K : /-! ### Weighted sums and gluing -/ -theorem weightedSum_glue (U : Finset (Fin n)) (w : Fin n → ℝ) +private theorem weightedSum_glue (U : Finset (Fin n)) (w : Fin n → ℝ) (p : U → Bool) (q : ↥Uᶜ → Bool) : weightedSum w (glue U p q) = weightedSum w (glue U p fun _ => false) + diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Menus.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Menus.lean index 2de5970b1..04fca4c7d 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Menus.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Menus.lean @@ -235,7 +235,7 @@ theorem directionMenuSum_pos_of_nonempty (p : Program signature n g) (dir : Fin /-! ### Static menu precomputation and block decomposition -/ /-- A linear threshold predicate `decide (θ ≤ c * t + β)` changes at most once along `ℝ`. -/ -theorem changesAtMost_linear_threshold (θ c β : ℝ) : +private theorem changesAtMost_linear_threshold (θ c β : ℝ) : ChangesAtMost (fun t : ℝ => decide (θ ≤ c * t + β)) 1 := by have hbase : ChangesAtMost (fun u : ℝ => decide (θ ≤ u)) 1 := by intro z hz S hS diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/PendingBias.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/PendingBias.lean index 1caa5b902..c38dba654 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/PendingBias.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/PendingBias.lean @@ -425,7 +425,7 @@ theorem eval_eq_of_inputSummary_eq (p : Program signature n g) {x y : Fin n → /-- If `summary x` determines the direct input summary of `enc x y` for every `y`, then equal summaries force identical row functions `f x₁ = f x₂`. -/ -theorem f_eq_of_summary_eq {X Y α : Type*} (p : Program signature n g) +private theorem f_eq_of_summary_eq {X Y α : Type*} (p : Program signature n g) (enc : X → Y → (Fin n → Bool)) (readout : (Fin g → Bool) → Bool) (f : X → Y → Bool) (summary : X → α) (hcomp : ∀ x y, readout (p.eval interpretation (enc x y)) = f x y) @@ -476,7 +476,7 @@ def intSummary {ι : Type*} [Fintype ι] {r : ℕ} (R : Fin r → ι → ℤ) (u /-- Each row `a` of `intSummary R` takes at most `1 + ∑ i, (R a i).natAbs` values on the Boolean cube. -/ -theorem card_intSummary_le_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {r : ℕ} +private theorem card_intSummary_le_prod {ι : Type*} [Fintype ι] [DecidableEq ι] {r : ℕ} (R : Fin r → ι → ℤ) : (univ.image (intSummary R)).card ≤ ∏ a : Fin r, (1 + ∑ i : ι, (R a i).natAbs) := by have hle := card_image_le_of_factorsThrough (intSummary R) @@ -553,7 +553,7 @@ private theorem pendingBiasTrace_add_eq_of_pendingBiasTrace_eq (p : Program sign /-- Under phased input access across cut `k`, the pending-bias state `pendingBiasTrace p (enc x y₀) k` at a reference right input `y₀` determines the entire row `f x`. -/ -theorem f_eq_of_pendingBiasTrace_eq_of_phased {X Y : Type*} (p : Program signature n g) +private theorem f_eq_of_pendingBiasTrace_eq_of_phased {X Y : Type*} (p : Program signature n g) (enc : X → Y → (Fin n → Bool)) (readout : (Fin g → Bool) → Bool) (f : X → Y → Bool) (k : ℕ) (y₀ : Y) (hcomp : ∀ x y, readout (p.eval interpretation (enc x y)) = f x y) diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Potential.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Potential.lean index 23acf8e0b..4cc907c9c 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Potential.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/Potential.lean @@ -139,12 +139,12 @@ def score (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : ℝ := P.inputSum i x + P.internalSum i z - P.threshold i /-- Every gate score has absolute value at least `1`. -/ -theorem one_le_abs_score' (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : +private theorem one_le_abs_score' (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : 1 ≤ |P.score x z i| := P.one_le_abs_score x z i /-- Every gate score is either at most `-1` or at least `1`. -/ -theorem score_le_neg_one_or_one_le (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : +private theorem score_le_neg_one_or_one_le (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : P.score x z i ≤ -1 ∨ 1 ≤ P.score x z i := by have h := P.one_le_abs_score' x z i rcases le_total 0 (P.score x z i) with h0 | h0 @@ -191,7 +191,7 @@ theorem score_congr_lt (x : Fin n → Bool) {z₁ z₂ : Fin g → Bool} {i : Fi simp only [score, P.internalSum_congr_lt h] /-- Updating coordinate `j ≥ i` leaves gate `i`'s score unchanged. -/ -theorem score_update_of_le (x : Fin n → Bool) (z : Fin g → Bool) {i j : Fin g} +private theorem score_update_of_le (x : Fin n → Bool) (z : Fin g → Bool) {i j : Fin g} (hij : i ≤ j) (b : Bool) : P.score x (Function.update z j b) i = P.score x z i := P.score_congr_lt x fun _ hki => Function.update_of_ne (ne_of_lt (lt_of_lt_of_le hki hij)) b z @@ -218,14 +218,14 @@ theorem sweep_zero (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n (z : Fin g → Bool) : P.sweep fixed val x z 0 = z := rfl -theorem sweep_succ (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) +private theorem sweep_succ (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) (z : Fin g → Bool) (k : ℕ) : P.sweep fixed val x z (k + 1) = if hk : k < g then P.faceStep fixed val x (P.sweep fixed val x z k) ⟨k, hk⟩ else P.sweep fixed val x z k := rfl /-- Once coordinate `i` has been swept at step `i + 1`, later sweep steps leave it unchanged. -/ -theorem sweep_eq_of_lt (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) +private theorem sweep_eq_of_lt (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) (z : Fin g → Bool) {i : Fin g} {k : ℕ} (hik : i.val < k) : P.sweep fixed val x z k i = P.sweep fixed val x z (i.val + 1) i := by induction k with @@ -240,7 +240,7 @@ theorem sweep_eq_of_lt (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin /-- At step `i + 1`, coordinate `i` is set according to the face rule on the state after `i` steps. -/ -theorem sweep_succ_self (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) +private theorem sweep_succ_self (fixed : Finset (Fin g)) (val : Fin g → Bool) (x : Fin n → Bool) (z : Fin g → Bool) (i : Fin g) : P.sweep fixed val x z (i.val + 1) i = if i ∈ fixed then val i else decide (0 < P.score x (P.sweep fixed val x z i.val) i) := by @@ -494,14 +494,14 @@ decreasing_by omega /-- Unfolding equation for the backwards priority `P.priority i`. -/ -theorem priority_eq (i : Fin g) : +private theorem priority_eq (i : Fin g) : P.priority i = 1 + ∑ j : Fin g, if i < j then P.priority j * |P.gateWeight j i| else 0 := by rw [priority] congr 1 exact sum_attach univ fun j => if i < j then P.priority j * |P.gateWeight j i| else 0 /-- Every gate priority is at least `1`. -/ -theorem one_le_priority (i : Fin g) : 1 ≤ P.priority i := by +private theorem one_le_priority (i : Fin g) : 1 ≤ P.priority i := by suffices ∀ k : ℕ, ∀ i : Fin g, g - 1 - i.val = k → 1 ≤ P.priority i from this _ i rfl intro k induction k using Nat.strong_induction_on with @@ -522,7 +522,7 @@ theorem priority_pos (i : Fin g) : 0 < P.priority i := /-- The total contribution of later gates `j > i` to coordinate `i`'s flip difference has magnitude at most `P.priority i - 1`. -/ -theorem abs_sum_later_le_priority_sub_one (z : Fin g → Bool) (i : Fin g) : +private theorem abs_sum_later_le_priority_sub_one (z : Fin g → Bool) (i : Fin g) : |∑ j : Fin g, if i < j then P.priority j * P.gateWeight j i * (z j).toNat else 0| ≤ P.priority i - 1 := by refine (abs_sum_le_sum_abs _ _).trans ?_ @@ -663,7 +663,8 @@ theorem energy_update_true_sub_false (x : Fin n → Bool) (z : Fin g → Bool) ( /-- When `0 < P.score x z i`, setting `z_i = true` decreases the energy by at least `1` relative to `z_i = false`. -/ -theorem energy_update_true_add_one_le_false {x : Fin n → Bool} {z : Fin g → Bool} {i : Fin g} +private theorem energy_update_true_add_one_le_false {x : Fin n → Bool} {z : Fin g → Bool} + {i : Fin g} (h : 0 < P.score x z i) : P.energy x (Function.update z i true) + 1 ≤ P.energy x (Function.update z i false) := by have h1 : 1 ≤ P.score x z i := (P.pos_score_iff_one_le x z i).mp h @@ -675,7 +676,8 @@ theorem energy_update_true_add_one_le_false {x : Fin n → Bool} {z : Fin g → /-- When `¬ (0 < P.score x z i)`, setting `z_i = false` decreases the energy by at least `1` relative to `z_i = true`. -/ -theorem energy_update_false_add_one_le_true {x : Fin n → Bool} {z : Fin g → Bool} {i : Fin g} +private theorem energy_update_false_add_one_le_true {x : Fin n → Bool} {z : Fin g → Bool} + {i : Fin g} (h : ¬ 0 < P.score x z i) : P.energy x (Function.update z i false) + 1 ≤ P.energy x (Function.update z i true) := by have h1 : P.score x z i ≤ -1 := @@ -751,7 +753,7 @@ theorem isSink_iff_eq_eval (x : Fin n → Bool) (z : Fin g → Bool) : /-- Updating coordinate `i` via `P.faceStep fixed val x` does not increase `P.energy x` whenever `z` already agrees with `val` at `i` if `i ∈ fixed`. -/ -theorem energy_faceStep_le {fixed : Finset (Fin g)} {val : Fin g → Bool} {x : Fin n → Bool} +private theorem energy_faceStep_le {fixed : Finset (Fin g)} {val : Fin g → Bool} {x : Fin n → Bool} {z : Fin g → Bool} {i : Fin g} (hfix : i ∈ fixed → z i = val i) : P.energy x (P.faceStep fixed val x z i) ≤ P.energy x z := by unfold faceStep diff --git a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/ScalarActivity.lean b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/ScalarActivity.lean index 55786de8d..a2d646918 100644 --- a/Complexity/Computability/Circuit/Boolean/WeightedThreshold/ScalarActivity.lean +++ b/Complexity/Computability/Circuit/Boolean/WeightedThreshold/ScalarActivity.lean @@ -169,7 +169,7 @@ theorem eval_eq_of_scalarScore_eq (p : Program signature n g) (w : Fin n → ℝ ring /-- Inputs with equal scalar score have identical input-reading transcripts. -/ -theorem transcript_eq_of_scalarScore_eq (p : Program signature n g) (w : Fin n → ℝ) +private theorem transcript_eq_of_scalarScore_eq (p : Program signature n g) (w : Fin n → ℝ) (hw : ∀ j : Fin g, ∃ c : ℝ, inputWeight p j = c • w) {x₁ x₂ : Fin n → Bool} (h : scalarScore w x₁ = scalarScore w x₂) : transcript p x₁ = transcript p x₂ := by @@ -192,7 +192,7 @@ noncomputable def leInputs (w : Fin n → ℝ) (t : ℝ) : Finset (Fin n → Boo open scoped Classical in /-- Input-reading transcripts realized by inputs with scalar score at most `t`. -/ -noncomputable def leTranscripts (p : Program signature n g) (w : Fin n → ℝ) (t : ℝ) : +private noncomputable def leTranscripts (p : Program signature n g) (w : Fin n → ℝ) (t : ℝ) : Finset (inputGates p → Bool) := (leInputs w t).image (transcript p) @@ -395,7 +395,8 @@ private theorem isChain_le_getElem {α : Type*} [Preorder α] {ts : List α} /-- Any ordered list `ts` along which `Φ` alternates between consecutive elements has length at most `T + 1` whenever `ChangesAtMost Φ T`. -/ -theorem length_le_succ_of_changesAtMost_of_isChain {α β : Type*} [Preorder α] {Φ : α → β} {T : ℕ} +private theorem length_le_succ_of_changesAtMost_of_isChain {α β : Type*} [Preorder α] {Φ : α → β} + {T : ℕ} (hΦ : ChangesAtMost Φ T) {ts : List α} (hmono : ts.IsChain (· ≤ ·)) (halt : (ts.map Φ).IsChain (· ≠ ·)) : ts.length ≤ T + 1 := by diff --git a/Complexity/Computability/Circuit/Boolean/Word.lean b/Complexity/Computability/Circuit/Boolean/Word.lean index 77c16587d..80a823f9c 100644 --- a/Complexity/Computability/Circuit/Boolean/Word.lean +++ b/Complexity/Computability/Circuit/Boolean/Word.lean @@ -171,7 +171,7 @@ section Arithmetic variable (a b : BitString n → BitVec w) /-- One carry chain uses four gates per bit and its initial constant. -/ -theorem word_carry (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) +private theorem word_carry (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) (hb : ∀ i : Fin w, (fun x => (b x).getLsbD i.val) ∈ s) (c : Bool) {t : ℕ} (ht : t ≤ w) : Synthesis interpretation s {fun x => BitVec.carry t (a x) (b x) c} (4 * t + 1) := by induction t with @@ -188,7 +188,7 @@ theorem word_carry (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) · omega /-- All carries of a sum, each computed once from the previous one. -/ -theorem word_carries (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) +private theorem word_carries (ha : ∀ i : Fin w, (fun x => (a x).getLsbD i.val) ∈ s) (hb : ∀ i : Fin w, (fun x => (b x).getLsbD i.val) ∈ s) (c : Bool) : Synthesis interpretation s (stages (fun t => {fun x => BitVec.carry t (a x) (b x) c}) w) (4 * w + 1) := by diff --git a/Complexity/Computability/Circuit/Clique.lean b/Complexity/Computability/Circuit/Clique.lean index 79c2296e8..c31077181 100644 --- a/Complexity/Computability/Circuit/Clique.lean +++ b/Complexity/Computability/Circuit/Clique.lean @@ -142,7 +142,7 @@ theorem contains_ofColoring_iff {c : Fin n → Fin r} {s : Finset (Fin n)} : /-- A set with all edges inside in the graph of a colouring with `r` colours has at most `r` vertices. -/ -theorem card_le_of_contains_ofColoring {c : Fin n → Fin r} {s : Finset (Fin n)} +private theorem card_le_of_contains_ofColoring {c : Fin n → Fin r} {s : Finset (Fin n)} (h : Contains (ofColoring c) s) : s.card ≤ r := by simpa using Finset.card_le_card_of_injOn c (fun _ _ => Finset.mem_univ _) (contains_ofColoring_iff.1 h) diff --git a/Complexity/Computability/Circuit/Cyclic/Feedback.lean b/Complexity/Computability/Circuit/Cyclic/Feedback.lean index b508a0765..21c6c1021 100644 --- a/Complexity/Computability/Circuit/Cyclic/Feedback.lean +++ b/Complexity/Computability/Circuit/Cyclic/Feedback.lean @@ -53,7 +53,7 @@ def feedbackWire (feed : Fin k → Fin g) : Wire (n + k) g → Wire n g := Wire.elim (Fin.addCases Wire.input (Wire.gate ∘ feed)) Wire.gate /-- Reading a feedback wire is reading the original wire with the selected gate values as state. -/ -theorem elim_feedbackWire (feed : Fin k → Fin g) (input : Fin n → U) (state : Fin g → U) +private theorem elim_feedbackWire (feed : Fin k → Fin g) (input : Fin n → U) (state : Fin g → U) (wire : Wire (n + k) g) : Wire.elim input state (feedbackWire feed wire) = Wire.elim (Fin.append input (state ∘ feed)) state wire := by diff --git a/Complexity/Computability/Circuit/Decomposable.lean b/Complexity/Computability/Circuit/Decomposable.lean index a06257be8..ef7044578 100644 --- a/Complexity/Computability/Circuit/Decomposable.lean +++ b/Complexity/Computability/Circuit/Decomposable.lean @@ -213,7 +213,7 @@ theorem rectangle_subset (v : N) : /-- A node accepting at least `K` assignments has fewer than `K` contexts, when the accepted set is `K`-rectangle-free. -/ -theorem ncard_contexts_le (hS : RectangleFree P.accepted K) {v : N} +private theorem ncard_contexts_le (hS : RectangleFree P.accepted K) {v : N} (hv : K ≤ (P.values v).ncard) : (P.contexts v).ncard ≤ K - 1 := by rcases hS.ncard_lt_or _ _ _ (P.rectangle_subset v) with h | h <;> omega @@ -231,7 +231,7 @@ def stops (K : ℕ) (v : N) : Set (ι → U) := /-- The threshold budget of a node: `(K - 1) ^ 2` for each child of a union and `(K - 1) ^ 3` for a product. -/ -def budget (K : ℕ) (v : N) : ℕ := +private def budget (K : ℕ) (v : N) : ℕ := match P.gate v with | .leaf => 0 | .union c => (K - 1) ^ 2 * c.card @@ -273,7 +273,7 @@ theorem exists_mem_stops (hK : 1 < K) (hS : K ≤ P.accepted.ncard) {x : ι → /-- **The charge at a node.** If the accepted set is `K`-rectangle-free, the descent stops at a node `v` for at most the budget of `v` inputs. -/ -theorem ncard_stops_le (hS : RectangleFree P.accepted K) (v : N) : +private theorem ncard_stops_le (hS : RectangleFree P.accepted K) (v : N) : (P.stops K v).ncard ≤ P.budget K v := by by_cases hlarge : K ≤ (P.values v).ncard swap diff --git a/Complexity/Computability/Circuit/Encoding/MapOp.lean b/Complexity/Computability/Circuit/Encoding/MapOp.lean index 8fc371a74..9fc6627c1 100644 --- a/Complexity/Computability/Circuit/Encoding/MapOp.lean +++ b/Complexity/Computability/Circuit/Encoding/MapOp.lean @@ -29,14 +29,15 @@ namespace Cslib.Circuits variable {σ τ : Signature} (φ : σ.Hom τ) {n g m : ℕ} /-- The code of a translated line: the translated operation on the same wires. -/ -theorem Line.code_mapOp (line : Line σ n g) : (line.mapOp φ).code = (φ line.op, line.code.2) := by +private theorem Line.code_mapOp (line : Line σ n g) : + (line.mapOp φ).code = (φ line.op, line.code.2) := by simp only [Line.code, Line.mapOp_op, Line.mapOp_wires] congr 1 rw [List.ofFn_congr (φ.arity_eq line.op)] simp /-- The code of a translated program: the operations of its gates translated. -/ -theorem Program.code_mapOp (p : Program σ n g) : +private theorem Program.code_mapOp (p : Program σ n g) : (p.mapOp φ).code = p.code.map fun g => (φ g.1, g.2) := by induction p with | empty => rfl diff --git a/Complexity/Computability/Circuit/Erase.lean b/Complexity/Computability/Circuit/Erase.lean index 994ec9e6f..ccfd9d39a 100644 --- a/Complexity/Computability/Circuit/Erase.lean +++ b/Complexity/Computability/Circuit/Erase.lean @@ -102,7 +102,7 @@ def Program.replaceGates : {s : ℕ} → Program σ n s → (Fin s → Option P) ((r (Fin.last _)).elim line.liftConstants Line.const) /-- The lines of a program with gates replaced by constants. -/ -theorem Program.lines_replaceGates (p : Program σ n s) (r : Fin s → Option P) (g : Fin s) : +private theorem Program.lines_replaceGates (p : Program σ n s) (r : Fin s → Option P) (g : Fin s) : (p.replaceGates r).lines g = (r g).elim (p.lines g).liftConstants Line.const := by induction p with | empty => exact g.elim0 @@ -131,17 +131,18 @@ theorem Program.lines_eraseGates (p : Program σ n s) (g : Fin s) : rw [eraseGates, lines_replaceGates] split_ifs <;> rfl -theorem Program.lines_eraseGates_of_special (p : Program σ n s) {g : Fin s} (hg : special g) : +private theorem Program.lines_eraseGates_of_special (p : Program σ n s) {g : Fin s} + (hg : special g) : (p.eraseGates special).lines g = Line.const ⟨g, hg⟩ := by simp only [lines_eraseGates, hg, ↓reduceDIte] -theorem Program.lines_eraseGates_of_not_special (p : Program σ n s) {g : Fin s} +private theorem Program.lines_eraseGates_of_not_special (p : Program σ n s) {g : Fin s} (hg : ¬special g) : (p.eraseGates special).lines g = (p.lines g).liftConstants := by simp only [lines_eraseGates, hg, ↓reduceDIte] /-- The arity of a gate of the erased program: zero for a special gate, and the arity of the gate otherwise. -/ -theorem Program.arity_lines_eraseGates (p : Program σ n s) (g : Fin s) : +private theorem Program.arity_lines_eraseGates (p : Program σ n s) (g : Fin s) : (σ.withConstants {g // special g}).Arity ((p.eraseGates special).lines g).op = if special g then 0 else σ.Arity (p.lines g).op := by by_cases hg : special g diff --git a/Complexity/Computability/Circuit/FanIn.lean b/Complexity/Computability/Circuit/FanIn.lean index 0db392b9a..09a2176b1 100644 --- a/Complexity/Computability/Circuit/FanIn.lean +++ b/Complexity/Computability/Circuit/FanIn.lean @@ -240,7 +240,7 @@ theorem Circuit.essential_le_size /-- In a program of fan-in `r`, a wire of depth `d` is supported by at most `max 1 r ^ d` inputs. -/ -theorem Program.card_wireSupport_le_pow {r : ℕ} : +private theorem Program.card_wireSupport_le_pow {r : ℕ} : ∀ {g : ℕ} {p : Program σ n g}, p.FanInAtMost r → ∀ w : Wire n g, (p.wireSupport w).card ≤ max 1 r ^ p.wireDepths w | _, .empty, _, .input i => by simp diff --git a/Complexity/Computability/Circuit/Frontier/AverageCase.lean b/Complexity/Computability/Circuit/Frontier/AverageCase.lean index ae039181d..44095c079 100644 --- a/Complexity/Computability/Circuit/Frontier/AverageCase.lean +++ b/Complexity/Computability/Circuit/Frontier/AverageCase.lean @@ -87,7 +87,7 @@ section Finite variable [Finite ι] [Finite U] /-- Membership in `S` agrees with membership in `T` or with membership in `Tᶜ`. -/ -theorem agreement_add_agreement_compl [Nonempty U] (S T : Set (ι → U)) : +private theorem agreement_add_agreement_compl [Nonempty U] (S T : Set (ι → U)) : agreement S T + agreement S Tᶜ = 1 := by have hN : (0 : ℝ) < Nat.card (ι → U) := by exact_mod_cast Nat.card_pos have hcompl : {x : ι → U | x ∈ S ↔ x ∈ Tᶜ} = {x | x ∈ S ↔ x ∈ T}ᶜ := by @@ -325,7 +325,7 @@ theorem agreement_le_of_layout {S : Set (Fin n → U)} {K : ℕ} {b : ℝ} degree three have layouts of width at most `(A + η) β₁ + η |V| + C`. If the inputs a circuit of fan-in at most two does not read carry fewer than `K` assignments, its graph has a layout of width at most `(A + η) (s - n + log_q K + 1) + η |V| + C` for `s` inner gates. -/ -theorem exists_layout_le {A η C : ℝ} (hAη : 0 ≤ A + η) +private theorem exists_layout_le {A η C : ℝ} (hAη : 0 ≤ A + η) (hC : ∀ (V E : Type) [Finite V] [Finite E] (G : Multigraph V E), G.toSimpleGraph.Connected → G.Loopless → G.MaxDegreeLE 3 → ∃ π : Layout V, (G.width π : ℝ) ≤ (A + η) * G.cycleRank + η * Nat.card V + C) diff --git a/Complexity/Computability/Circuit/Frontier/BranchingProgram.lean b/Complexity/Computability/Circuit/Frontier/BranchingProgram.lean index 58012fa92..80625575e 100644 --- a/Complexity/Computability/Circuit/Frontier/BranchingProgram.lean +++ b/Complexity/Computability/Circuit/Frontier/BranchingProgram.lean @@ -225,14 +225,14 @@ def SmallSides (K : ℕ) : Prop := (P.sweep.pastSide t x).ncard < K ∨ (P.sweep.futureSide t x).ncard < K /-- A rectangle-free accepted set has small sides. -/ -theorem smallSides_of_rectangleFree {K : ℕ} (hS : RectangleFree P.accepted K) : +private theorem smallSides_of_rectangleFree {K : ℕ} (hS : RectangleFree P.accepted K) : P.SmallSides K := fun t _ x _ => P.sweep.pastSide_lt_or_futureSide_lt hS t x variable {P} in /-- Small sides force `K > 1` once some input is accepted: at the first layer both sides of an accepted input are nonempty. -/ -theorem SmallSides.one_lt [Finite ι] [Finite U] {K : ℕ} (hS : P.SmallSides K) +private theorem SmallSides.one_lt [Finite ι] [Finite U] {K : ℕ} (hS : P.SmallSides K) (hne : P.accepted.Nonempty) : 1 < K := by obtain ⟨x, hx⟩ := hne rcases hS 0 (Nat.zero_le _) x hx with h | h @@ -295,7 +295,7 @@ def eraseNode (t : ℕ) (m : M) : ReadOnceNBP ι U M := variable {P} -theorem IsAcceptingPath.of_eraseNode {t : ℕ} {m : M} {x : ι → U} {γ : ℕ → M} +private theorem IsAcceptingPath.of_eraseNode {t : ℕ} {m : M} {x : ι → U} {γ : ℕ → M} (h : (P.eraseNode t m).IsAcceptingPath x γ) : P.IsAcceptingPath x γ := ⟨h.start, h.accept, fun s hs => (h.edge s hs).1⟩ @@ -318,7 +318,7 @@ theorem isAcceptingPath_eraseNode_iff (hL : 0 < P.length) {t : ℕ} (ht : t ≤ · rintro ⟨rfl, hs'⟩ exact hγ hs' -theorem Unambiguous.eraseNode (hP : P.Unambiguous) (t : ℕ) (m : M) : +private theorem Unambiguous.eraseNode (hP : P.Unambiguous) (t : ℕ) (m : M) : (P.eraseNode t m).Unambiguous := fun x γ δ hγ hδ s hs => hP x γ δ hγ.of_eraseNode hδ.of_eraseNode s hs diff --git a/Complexity/Computability/Circuit/Frontier/Compiler.lean b/Complexity/Computability/Circuit/Frontier/Compiler.lean index 6c354e6dc..b09cd9bbc 100644 --- a/Complexity/Computability/Circuit/Frontier/Compiler.lean +++ b/Complexity/Computability/Circuit/Frontier/Compiler.lean @@ -85,7 +85,7 @@ theorem loopless : (graph c).Loopless := by rcases t with a | o <;> cases h /-- A gate has at most `r` argument slots when the fan-in is at most `r`. -/ -theorem ncard_slot_le {r : ℕ} (hfan : c.FanInAtMost r) (w : Wire n c.size) : +private theorem ncard_slot_le {r : ℕ} (hfan : c.FanInAtMost r) (w : Wire n c.size) : {a : Slot c | Wire.gate a.1.1 = w}.ncard ≤ r := by calc {a : Slot c | Wire.gate a.1.1 = w}.ncard ≤ ((Finset.range r : Finset ℕ) : Set ℕ).ncard := by @@ -98,7 +98,7 @@ theorem ncard_slot_le {r : ℕ} (hfan : c.FanInAtMost r) (w : Wire n c.size) : _ = r := by rw [ncard_coe_finset, Finset.card_range] /-- Two junctions fed by the same junction are equal. -/ -theorem eq_of_feeder_eq_junction : +private theorem eq_of_feeder_eq_junction : ∀ {j₁ j₂ j : Junction c}, feeder j₁ = .junction j → feeder j₂ = .junction j → j₁ = j₂ | ⟨_, ⟨0, _⟩⟩, _, _, h₁, _ => by cases h₁ | ⟨_, ⟨_ + 1, _⟩⟩, ⟨_, ⟨0, _⟩⟩, _, _, h₂ => by cases h₂ @@ -166,7 +166,7 @@ theorem maxDegreeLE {r : ℕ} (hr : 2 ≤ r) (hfan : c.FanInAtMost r) : /-! ### Connectivity -/ /-- The junctions of a signal are joined to its vertex along their chain. -/ -theorem reachable_junction_signal (w : Signal c) : +private theorem reachable_junction_signal (w : Signal c) : ∀ (k : ℕ) (hk : k < fanout c w), (graph c).toSimpleGraph.Reachable (.junction ⟨w, ⟨k, hk⟩⟩) (.signal w) | 0, hk => ((graph c).reachable_src_tgt (.feed ⟨w, ⟨0, hk⟩⟩)).symm @@ -174,12 +174,12 @@ theorem reachable_junction_signal (w : Signal c) : (reachable_junction_signal w k (by omega)) /-- Every junction is joined to the vertex of its signal. -/ -theorem reachable_junction (j : Junction c) : +private theorem reachable_junction (j : Junction c) : (graph c).toSimpleGraph.Reachable (.junction j) (.signal j.1) := reachable_junction_signal j.1 j.2 j.2.isLt /-- The vertex of a signal is joined to each of its consumers. -/ -theorem reachable_owner (t : Consumer c) : +private theorem reachable_owner (t : Consumer c) : (graph c).toSimpleGraph.Reachable (.signal (consumed t)) (owner t) := by have h := ((graph c).reachable_src_tgt (deliverEdge t)).symm rw [graph_tgt, tgt_deliverEdge] at h @@ -187,7 +187,7 @@ theorem reachable_owner (t : Consumer c) : exact (h.trans (reachable_junction _)).symm /-- The vertex of every signal is joined to the vertex of some output. -/ -theorem exists_reachable_signal_output (w : Signal c) : +private theorem exists_reachable_signal_output (w : Signal c) : ∃ o, (graph c).toSimpleGraph.Reachable (.signal w) (.output o) := by obtain ⟨w, hw⟩ := w induction hw with @@ -197,7 +197,7 @@ theorem exists_reachable_signal_output (w : Signal c) : exact ⟨o, (reachable_owner (.inl ⟨⟨_, a⟩, hg⟩)).trans ho⟩ /-- Every vertex is joined to the vertex of some output. -/ -theorem exists_reachable_output (v : Vertex c) : +private theorem exists_reachable_output (v : Vertex c) : ∃ o, (graph c).toSimpleGraph.Reachable v (.output o) := by cases v with | signal w => exact exists_reachable_signal_output w @@ -262,7 +262,7 @@ theorem ncard_readAt_le (v : Vertex c) : ((network c I Acc).readAt v).ncard ≤ exact Wire.input.inj (congrArg Subtype.val (Vertex.signal.inj h)) /-- The inputs read in a set of vertices are the reachable inputs whose vertex lies in it. -/ -theorem readIn_network (W : Set (Vertex c)) : +private theorem readIn_network (W : Set (Vertex c)) : (network c I Acc).readIn W = {i | ∃ hi : Reach c (.input i), .signal ⟨.input i, hi⟩ ∈ W} := by ext i constructor @@ -273,7 +273,7 @@ theorem readIn_network (W : Set (Vertex c)) : exact ⟨_, hv, site_of_reach hi⟩ /-- Signals are reachable inputs and reachable gates. -/ -def signalEquiv : +private def signalEquiv : Signal c ≃ {i : Fin n // Reach c (.input i)} ⊕ {g : Fin c.size // Reach c (.gate g)} where toFun | ⟨.input i, h⟩ => .inl ⟨i, h⟩ @@ -295,13 +295,14 @@ abbrev InnerGateIn (W : Set (Vertex c)) : Type := {g : InnerGate c // Vertex.signal ⟨.gate g.1, g.2.1⟩ ∈ W} /-- The reachable inner gates are inner gates. -/ -theorem card_innerGate_le : Nat.card (InnerGate c) ≤ c.innerSize := by +private theorem card_innerGate_le : Nat.card (InnerGate c) ≤ c.innerSize := by rw [Circuit.innerSize, ← Nat.card_eq_finsetCard] exact Nat.card_le_card_of_injective (fun g => ⟨g.1, Program.mem_innerGates.mpr g.2.2⟩) fun _ _ h => Subtype.ext (congrArg Subtype.val h :) /-- The reachable inner gates in `W` are inner gates. -/ -theorem card_innerGateIn_le (W : Set (Vertex c)) : Nat.card (InnerGateIn c W) ≤ c.innerSize := +private theorem card_innerGateIn_le (W : Set (Vertex c)) : + Nat.card (InnerGateIn c W) ≤ c.innerSize := (Finite.card_subtype_le _).trans card_innerGate_le /-- There are at least as many reachable gates as reachable inner gates. -/ @@ -311,7 +312,7 @@ theorem card_innerGate_le_card_gate : Subtype.ext (congrArg Subtype.val h :) /-- There are at most `r` slots per reachable inner gate in `W`; constant gates have none. -/ -theorem card_slot_le {r : ℕ} (hfan : c.FanInAtMost r) (W : Set (Vertex c)) : +private theorem card_slot_le {r : ℕ} (hfan : c.FanInAtMost r) (W : Set (Vertex c)) : Nat.card {t : Slot c // owner (.inl t) ∈ W} ≤ r * Nat.card (InnerGateIn c W) := by calc Nat.card {t : Slot c // owner (.inl t) ∈ W} ≤ Nat.card (InnerGateIn c W × Fin r) := by @@ -331,17 +332,17 @@ theorem card_edge : Nat.card (Edge c) = 2 * Nat.card (Consumer c) := by rw [Nat.card_congr Edge.equiv, Nat.card_sum, Nat.card_congr (junctionEquiv c), two_mul] /-- There is one vertex per signal, per consumer, and per output. -/ -theorem card_vertex : +private theorem card_vertex : Nat.card (Vertex c) = Nat.card (Signal c) + Nat.card (Consumer c) + m := by rw [Nat.card_congr Vertex.equiv, Nat.card_sum, Nat.card_sum, Nat.card_congr (junctionEquiv c), Nat.card_eq_fintype_card (α := Fin m), Fintype.card_fin, add_assoc] /-- The consumers are the argument slots of reachable gates and the outputs. -/ -theorem card_consumer : Nat.card (Consumer c) = Nat.card (Slot c) + m := by +private theorem card_consumer : Nat.card (Consumer c) = Nat.card (Slot c) + m := by rw [Nat.card_sum, Nat.card_eq_fintype_card (α := Fin m), Fintype.card_fin] /-- Every signal has a consumer, so there are at least as many consumers as signals. -/ -theorem card_signal_le_card_consumer : Nat.card (Signal c) ≤ Nat.card (Consumer c) := by +private theorem card_signal_le_card_consumer : Nat.card (Signal c) ≤ Nat.card (Consumer c) := by rw [← Nat.card_congr (junctionEquiv c)] exact Nat.card_le_card_of_injective (fun w => ⟨w, ⟨0, fanout_pos w⟩⟩) fun w w' h => congrArg Sigma.fst h @@ -401,7 +402,7 @@ private theorem ncard_readIn_add_card_le (W : Set (Vertex c)) : /-- **The count inside a closed set, gate by gate.** For fan-in at most `r`, the edges at a closed set of vertices `W` and the inputs read in `W` number at most `(r - 1) s_W` more than the vertices of `W`, where `s_W` counts the reachable inner gates in `W`. -/ -theorem ncard_touching_add_ncard_readIn_le_card_innerGateIn {r : ℕ} (hfan : c.FanInAtMost r) +private theorem ncard_touching_add_ncard_readIn_le_card_innerGateIn {r : ℕ} (hfan : c.FanInAtMost r) {W : Set (Vertex c)} (hW : (graph c).edgeCut W = ∅) : ((graph c).touching W).ncard + ((network c I Acc).readIn W).ncard ≤ W.ncard + (r - 1) * Nat.card (InnerGateIn c W) := by @@ -443,7 +444,7 @@ theorem cycleRankOn_add_ncard_readIn_le {r : ℕ} (hfan : c.FanInAtMost r) /-- **The edge count.** For fan-in at most `r`, the edges of the graph and the inputs read by the network number at most `(r - 1) s` more than the vertices, where `s` counts the inner gates. This is the count inside the closed set of all vertices. -/ -theorem card_edge_add_ncard_read_le {r : ℕ} (hfan : c.FanInAtMost r) : +private theorem card_edge_add_ncard_read_le {r : ℕ} (hfan : c.FanInAtMost r) : Nat.card (Edge c) + (network c I Acc).read.ncard ≤ Nat.card (Vertex c) + (r - 1) * c.innerSize := by have h := ncard_touching_add_ncard_readIn_le I Acc hfan (graph c).edgeCut_univ diff --git a/Complexity/Computability/Circuit/Frontier/Compiler/Network.lean b/Complexity/Computability/Circuit/Frontier/Compiler/Network.lean index 3a2cdae3e..ee96c7885 100644 --- a/Complexity/Computability/Circuit/Frontier/Compiler/Network.lean +++ b/Complexity/Computability/Circuit/Frontier/Compiler/Network.lean @@ -291,7 +291,7 @@ theorem eq_head_of_src_eq_signal : ∀ {e : Edge c} {w : Signal c}, src e = .sig | .deliver _, _, h => by cases h /-- An edge leaving a junction carries the signal of the junction. -/ -theorem signal_of_src_eq_junction : +private theorem signal_of_src_eq_junction : ∀ {e : Edge c} {j : Junction c}, src e = .junction j → e.signal = j.1 | .feed ⟨_, ⟨0, _⟩⟩, _, h => by cases h | .feed ⟨_, ⟨_ + 1, _⟩⟩, _, h => by cases h; rfl @@ -426,21 +426,21 @@ include hα /-- In a satisfying assignment, the feed edges along the chain of junctions of a signal carry the value of its first edge. -/ -theorem feed_eq_head (w : Signal c) : +private theorem feed_eq_head (w : Signal c) : ∀ (k : ℕ) (hk : k < fanout c w), α (.feed ⟨w, ⟨k, hk⟩⟩) = α (head w) | 0, _ => rfl | k + 1, hk => (hα (.junction ⟨w, ⟨k, by omega⟩⟩) _ rfl).trans (feed_eq_head w k _) /-- In a satisfying assignment, every edge carries the value of the first edge of its signal. -/ -theorem eq_head (e : Edge c) : α e = α (head e.signal) := by +private theorem eq_head (e : Edge c) : α e = α (head e.signal) := by rcases e with ⟨w, k⟩ | ⟨w, k⟩ · exact feed_eq_head hα w k k.isLt · exact (hα (.junction ⟨w, k⟩) (.deliver ⟨w, k⟩) rfl).trans (feed_eq_head hα w k k.isLt) /-- In a satisfying assignment, the first edge of every signal carries its value in the circuit. -/ -theorem head_eq_trace : +private theorem head_eq_trace : ∀ (w : Wire n c.size) (hw : Reach c w), α (head ⟨w, hw⟩) = c.program.trace I x w := by refine c.program.wire_induction (fun i hw => hα (.signal ⟨.input i, hw⟩)) fun g ih hw => ?_ have h : α (head ⟨.gate g, hw⟩) = I _ fun a => α (argEdge hw a) := hα (.signal ⟨.gate g, hw⟩) diff --git a/Complexity/Computability/Circuit/Frontier/Correlation.lean b/Complexity/Computability/Circuit/Frontier/Correlation.lean index b7d3d87b2..b68b2ff7e 100644 --- a/Complexity/Computability/Circuit/Frontier/Correlation.lean +++ b/Complexity/Computability/Circuit/Frontier/Correlation.lean @@ -111,7 +111,7 @@ universe v /-- The threshold and the rate of the Gaussian layout coefficient `A = 2p` in closed form: `c* = 1 + π / (6 arccos ((1 + 2√2)/4))` and `L = 1 + π / (3 arccos ((1 + 2√2)/4))`. -/ -theorem gaussian_rate_eq (c : ℝ) : +private theorem gaussian_rate_eq (c : ℝ) : (1 + 1 / (2 * (2 * Gaussian.gaussianCoefficient)) - c) / (2 * (1 + 1 / (2 * Gaussian.gaussianCoefficient))) = (1 + π / (6 * arccos ((1 + 2 * √2) / 4)) - c) / @@ -179,7 +179,7 @@ theorem rightHalf_injective (n : ℕ) : Function.Injective (rightHalf n) := fun a b h => Fin.ext (by simpa [rightHalf] using congrArg Fin.val h) /-- The two halves are disjoint. -/ -theorem disjoint_range_leftHalf_rightHalf (n : ℕ) : +private theorem disjoint_range_leftHalf_rightHalf (n : ℕ) : Disjoint (range (leftHalf n)) (range (rightHalf n)) := by rw [Set.disjoint_left] rintro _ ⟨a, rfl⟩ ⟨b, hb⟩ @@ -227,7 +227,7 @@ theorem half_le_cutRank_hardMatrix (n : ℕ) {U : Set (Fin n)} (hU : U.ncard = n (by rw [Nat.card_eq_fintype_card, Fintype.card_fin]; omega) hU /-- The deficiency `2 (2 ⌊√⌊n/2⌋⌋ + 1) + 1` of the chosen family is sublinear. -/ -theorem isLittleO_hardDeficiency : +private theorem isLittleO_hardDeficiency : (fun n : ℕ => ((2 * (2 * Nat.sqrt (n / 2) + 1) + 1 : ℕ) : ℝ)) =o[atTop] fun n => (n : ℝ) := by rw [isLittleO_iff] intro ε hε @@ -255,7 +255,7 @@ theorem isLittleO_hardDeficiency : linarith /-- The bisection hypothesis for the chosen family, in the form used by the asymptotic bounds. -/ -theorem half_le_cutRank_hardMatrix_add (n : ℕ) (U : Set (Fin n)) (hU : U.ncard = n / 2) : +private theorem half_le_cutRank_hardMatrix_add (n : ℕ) (U : Set (Fin n)) (hU : U.ncard = n / 2) : ((n / 2 : ℕ) : ℝ) ≤ (hardMatrix n + (hardMatrix n)ᵀ).cutRank U + ((2 * (2 * Nat.sqrt (n / 2) + 1) + 1 : ℕ) : ℝ) := by exact_mod_cast half_le_cutRank_hardMatrix n hU diff --git a/Complexity/Computability/Circuit/Frontier/Correlation/Asymptotics.lean b/Complexity/Computability/Circuit/Frontier/Correlation/Asymptotics.lean index f60b1be28..446d58ce6 100644 --- a/Complexity/Computability/Circuit/Frontier/Correlation/Asymptotics.lean +++ b/Complexity/Computability/Circuit/Frontier/Correlation/Asymptotics.lean @@ -65,7 +65,7 @@ private theorem abs_le_two_rpow_of_sq_le {y γ : ℝ} {n : ℕ} /-- The rate in two forms: `2 (c* - c)/(2L) = (1/2 - A (c - 1)) / (1 + A)`, where `c* = 1 + 1/(2A)` and `L = 1 + 1/A`. -/ -theorem two_mul_rate_eq {A c : ℝ} (hA : 0 < A) : +private theorem two_mul_rate_eq {A c : ℝ} (hA : 0 < A) : 2 * ((1 + 1 / (2 * A) - c) / (2 * (1 + 1 / A))) = (1 / 2 - A * (c - 1)) / (1 + A) := by field_simp ring diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Basic.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Basic.lean index 8d89894ce..9a3a0be97 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Basic.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Basic.lean @@ -41,7 +41,7 @@ namespace Cslib.Circuits.Frontier open Set /-- `log₂ N` is at most `ε N` plus a constant, for every `ε > 0`. -/ -theorem exists_natLog_le_mul_add {ε : ℝ} (hε : 0 < ε) : +private theorem exists_natLog_le_mul_add {ε : ℝ} (hε : 0 < ε) : ∃ K : ℝ, ∀ N : ℕ, (Nat.log 2 N : ℝ) ≤ ε * N + K := by obtain ⟨k, hk⟩ := pow_unbounded_of_one_lt (1 / ε) one_lt_two refine ⟨k, fun N => ?_⟩ diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/BoundedDegree.lean b/Complexity/Computability/Circuit/Frontier/Layouts/BoundedDegree.lean index c7a581aab..516f8fc47 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/BoundedDegree.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/BoundedDegree.lean @@ -59,7 +59,7 @@ noncomputable def degreeCoefficient (d : ℕ) : ℝ := 3 * d / (2 * d - 3) * vertexCoefficient d /-- The limiting adjacent correlation `2 √(d - 1) / d` is less than one for `d ≥ 3`. -/ -theorem vertexCorrelation_lt_one {d : ℕ} (hd : 3 ≤ d) : vertexCorrelation d < 1 := by +private theorem vertexCorrelation_lt_one {d : ℕ} (hd : 3 ≤ d) : vertexCorrelation d < 1 := by have hD : (3 : ℝ) ≤ d := by exact_mod_cast hd have hs : √((d : ℝ) - 1) ^ 2 = d - 1 := sq_sqrt (by linarith) rw [vertexCorrelation, div_lt_one (by linarith)] diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Compression.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Compression.lean index d5197b4e4..833270f1e 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Compression.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Compression.lean @@ -94,7 +94,7 @@ variable {G : Multigraph V E} {d : ℕ} /-! ### Merging -/ /-- The compression into single vertices. -/ -def singletons [Fintype V] [DecidableEq V] [Finite E] (hG : G.MaxDegreeLE d) : +private def singletons [Fintype V] [DecidableEq V] [Finite E] (hG : G.MaxDegreeLE d) : Compression G d where blocks := Finset.univ.image fun v => [v] exists_mem v := ⟨[v], Finset.mem_image_of_mem _ (Finset.mem_univ v), @@ -120,7 +120,7 @@ variable (c : Compression G d) /-- **Merging.** Two distinct blocks joined by an edge, with at most `d` edges leaving their union, may be replaced by their union, listing the longer block first. -/ -theorem exists_merge [Finite E] {B B' : List V} (hB : B ∈ c.blocks) (hB' : B' ∈ c.blocks) +private theorem exists_merge [Finite E] {B B' : List V} (hB : B ∈ c.blocks) (hB' : B' ∈ c.blocks) (hne : B ≠ B') (hjoin : (G.edgeCut {v | v ∈ B} ∩ G.edgeCut {v | v ∈ B'}).Nonempty) (hcut : (G.edgeCut ({v | v ∈ B} ∪ {v | v ∈ B'})).ncard ≤ d) : ∃ c' : Compression G d, c'.blocks.card < c.blocks.card := by @@ -274,7 +274,7 @@ theorem mem_iff_blockOf_eq {v : V} {B : c.blocks} : v ∈ B.1 ↔ c.blockOf v = fun h => h ▸ c.mem_blockOf v⟩ /-- The vertices of a block are those it contains. -/ -theorem preimage_blockOf_singleton (B : c.blocks) : c.blockOf ⁻¹' {B} = {v | v ∈ B.1} := by +private theorem preimage_blockOf_singleton (B : c.blocks) : c.blockOf ⁻¹' {B} = {v | v ∈ B.1} := by ext v simp [c.mem_iff_blockOf_eq] @@ -317,7 +317,7 @@ def external : Set E := {e | c.blockOf (G.src e) ≠ c.blockOf (G.tgt e)} /-- The edges outside the external edges are those inside a block. -/ -theorem compl_external : c.externalᶜ = {e | ∃ B ∈ c.blocks, G.src e ∈ B ∧ G.tgt e ∈ B} := by +private theorem compl_external : c.externalᶜ = {e | ∃ B ∈ c.blocks, G.src e ∈ B ∧ G.tgt e ∈ B} := by ext e simp only [external, mem_compl_iff, mem_ofPred_eq, not_not] constructor @@ -342,7 +342,7 @@ theorem quotient_loopless : c.quotient.Loopless := fun e => e.2 /-- The cut of a union of whole blocks consists of the edges of the cut of the quotient. -/ -theorem edgeCut_preimage (T : Set c.blocks) : +private theorem edgeCut_preimage (T : Set c.blocks) : G.edgeCut (c.blockOf ⁻¹' T) = Subtype.val '' c.quotient.edgeCut T := by ext e simp only [mem_edgeCut, mem_preimage, mem_image, Subtype.exists, exists_and_right, diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Cubic.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Cubic.lean index 93a9edba4..ddc254868 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Cubic.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Cubic.lean @@ -71,7 +71,7 @@ variable {V E : Type*} {G : Multigraph V E} {c : Compression G 3} /-- In a saturated compression with budget three, two distinct blocks are joined by at most one edge. -/ -theorem Saturated.ncard_edgeCut_inter_le_one [Finite E] (hc : c.Saturated) {B B' : c.blocks} +private theorem Saturated.ncard_edgeCut_inter_le_one [Finite E] (hc : c.Saturated) {B B' : c.blocks} (hne : B ≠ B') : (G.edgeCut {v | v ∈ B.1} ∩ G.edgeCut {v | v ∈ B'.1}).ncard ≤ 1 := by rcases (G.edgeCut {v | v ∈ B.1} ∩ G.edgeCut {v | v ∈ B'.1}).eq_empty_or_nonempty with h | h · simp [h] @@ -83,7 +83,7 @@ theorem Saturated.ncard_edgeCut_inter_le_one [Finite E] (hc : c.Saturated) {B B' /-- In a saturated compression with budget three of a connected multigraph into at least two blocks, exactly three edges leave each block. -/ -theorem Saturated.ncard_edgeCut_eq_three [Finite E] (hc : c.Saturated) +private theorem Saturated.ncard_edgeCut_eq_three [Finite E] (hc : c.Saturated) (hG : G.toSimpleGraph.Connected) (two : 1 < Nat.card c.blocks) (B : c.blocks) : (G.edgeCut {v | v ∈ B.1}).ncard = 3 := by obtain ⟨e, he⟩ := c.edgeCut_nonempty hG two B diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian.lean index 68d808b68..118618576 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian.lean @@ -80,7 +80,7 @@ namespace Cslib.Circuits.Frontier.Gaussian /-- **Decay rate and radius.** Every `ρ₀ < 2√2/3` admits a decay rate `q ≥ 0` and a radius `R` with `ρ₀ ≤ 2 q / (1 + q ^ 2) - 3 (2 q ^ 2) ^ R`. -/ -theorem exists_decay_radius {ρ₀ : ℝ} (hρ₀ : ρ₀ < 2 * √2 / 3) : +private theorem exists_decay_radius {ρ₀ : ℝ} (hρ₀ : ρ₀ < 2 * √2 / 3) : ∃ (q : ℝ) (R : ℕ), 0 ≤ q ∧ ρ₀ ≤ 2 * q / (1 + q ^ 2) - 3 * (2 * q ^ 2) ^ R := by have h3 : vertexCorrelation 3 = 2 * √2 / 3 := by norm_num [vertexCorrelation] obtain ⟨q, R, hq, hρ⟩ := exists_decay_radius_degree (by norm_num : 2 ≤ 3) (ρ := ρ₀) diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Basic.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Basic.lean index 02d13e5b9..94be638cd 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Basic.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Basic.lean @@ -171,7 +171,7 @@ section Deviations variable {Ω κ : Type*} [Fintype κ] /-- The number of events that occur is the sum of their indicators. -/ -theorem ncard_eq_sum_indicator (A : κ → Set Ω) (ω : Ω) : +private theorem ncard_eq_sum_indicator (A : κ → Set Ω) (ω : Ω) : ({k | ω ∈ A k}.ncard : ℝ) = ∑ k, (A k).indicator (1 : Ω → ℝ) ω := by classical simp only [indicator_apply, Pi.one_apply] @@ -179,7 +179,7 @@ theorem ncard_eq_sum_indicator (A : κ → Set Ω) (ω : Ω) : /-- Outside the event that the number of events that occur deviates from `m` by at least `c`, this number is below `m + c`. -/ -theorem ncard_lt_of_not_le_abs {A : κ → Set Ω} {ω : Ω} {m c : ℝ} +private theorem ncard_lt_of_not_le_abs {A : κ → Set Ω} {ω : Ω} {m c : ℝ} (h : ¬c ≤ |∑ k, (A k).indicator (1 : Ω → ℝ) ω - m|) : ({k | ω ∈ A k}.ncard : ℝ) < m + c := by rw [ncard_eq_sum_indicator] linarith [le_abs_self (∑ k, (A k).indicator (1 : Ω → ℝ) ω - m), not_le.mp h] @@ -248,7 +248,7 @@ variable {V : Type*} [Fintype V] /-- The product of standard Gaussians on `V → ℝ` carries an event about inner products to the same event under the standard Gaussian measure of `EuclideanSpace ℝ V`. -/ -theorem measureReal_pi_eq {s : Set (EuclideanSpace ℝ V)} (hs : MeasurableSet s) : +private theorem measureReal_pi_eq {s : Set (EuclideanSpace ℝ V)} (hs : MeasurableSet s) : (Measure.pi fun _ : V => gaussianReal 0 1).real {ω | WithLp.toLp 2 ω ∈ s} = (stdGaussian (EuclideanSpace ℝ V)).real s := (measurePreserving_toLp_pi_gaussianReal V).measureReal_preimage hs.nullMeasurableSet @@ -325,7 +325,7 @@ theorem le_inner_unitKernelRow_src_tgt [Finite E] (hloop : G.Loopless) {d : ℕ} end Correlations -theorem continuous_correlation : Continuous fun q : ℝ => 2 * q / (1 + q ^ 2) := +private theorem continuous_correlation : Continuous fun q : ℝ => 2 * q / (1 + q ^ 2) := (continuous_const.mul continuous_id).div (continuous_const.add (continuous_pow 2)) fun q => by positivity diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Sample.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Sample.lean index a9ec6b2f0..2765adc92 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Sample.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Gaussian/Sample.lean @@ -68,13 +68,13 @@ def edgeScoreEvent (q : ℝ) (R : ℕ) (p : ℝ → Prop) (e : E) : Set (V → variable {G} {q : ℝ} {R : ℕ} -theorem measurableSet_edgeScoreEvent (q : ℝ) (R : ℕ) {p : ℝ → Prop} +private theorem measurableSet_edgeScoreEvent (q : ℝ) (R : ℕ) {p : ℝ → Prop} (hp : MeasurableSet {x | p x}) (e : E) : MeasurableSet (edgeScoreEvent G q R p e) := measurable_edgeScore q R e hp /-- An event about the score of `e` depends only on the coordinates of the sample in the closed ball of radius `R + 1` around the source of `e`. -/ -theorem dependsOn_edgeScoreEvent (q : ℝ) (R : ℕ) (p : ℝ → Prop) (e : E) : +private theorem dependsOn_edgeScoreEvent (q : ℝ) (R : ℕ) (p : ℝ → Prop) (e : E) : DependsOn (· ∈ edgeScoreEvent G q R p e) (closedBall G.toSimpleGraph (G.src e) (R + 1)) := by intro ω ω' hω simp only [edgeScoreEvent, mem_ofPred_eq, edgeScore_congr (Or.inl rfl) hω] diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/General.lean b/Complexity/Computability/Circuit/Frontier/Layouts/General.lean index cda517c9b..d3a1ce823 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/General.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/General.lean @@ -60,7 +60,7 @@ def edgeRestrict (F : Set E) : Multigraph V F where variable {G} /-- Removing edges does not increase degrees. -/ -theorem MaxDegreeLE.edgeRestrict [Finite E] {d : ℕ} (hd : G.MaxDegreeLE d) (F : Set E) : +private theorem MaxDegreeLE.edgeRestrict [Finite E] {d : ℕ} (hd : G.MaxDegreeLE d) (F : Set E) : (G.edgeRestrict F).MaxDegreeLE d := by intro v rw [← ncard_image_of_injective _ Subtype.val_injective] diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Kernel.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Kernel.lean index 51718ebe4..3f3217da9 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Kernel.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Kernel.lean @@ -91,7 +91,7 @@ theorem kernelRow_comm (q : ℝ) (R : ℕ) (v z : V) : kernelRow G q R v z = ker simp only [kernelRow_apply, SimpleGraph.edist_comm (u := v), SimpleGraph.dist_comm (u := v)] /-- The kernel row of `v` vanishes outside the closed ball of radius `R` around `v`. -/ -theorem kernelRow_eq_zero_of_lt {q : ℝ} {R : ℕ} {v z : V} (h : R < G.edist v z) : +private theorem kernelRow_eq_zero_of_lt {q : ℝ} {R : ℕ} {v z : V} (h : R < G.edist v z) : kernelRow G q R v z = 0 := by rw [kernelRow_apply, ite_eq_right (not_le.2 h)] @@ -165,7 +165,7 @@ private theorem kernelRow_defect_le {q : ℝ} (R : ℕ) {u v : V} (huv : G.Adj u variable [Fintype V] /-- Every kernel row has norm at least one, from its entry `1` at its own vertex. -/ -theorem one_le_norm_kernelRow (q : ℝ) (R : ℕ) (v : V) : 1 ≤ ‖kernelRow G q R v‖ := by +private theorem one_le_norm_kernelRow (q : ℝ) (R : ℕ) (v : V) : 1 ≤ ‖kernelRow G q R v‖ := by have h : 1 ≤ ‖kernelRow G q R v‖ ^ 2 := by rw [EuclideanSpace.real_norm_sq_eq] calc (1 : ℝ) = kernelRow G q R v v ^ 2 := by rw [kernelRow_self, one_pow] diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Local.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Local.lean index 40802acaf..5678b994f 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Local.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Local.lean @@ -73,7 +73,8 @@ variable {V E : Type*} (G : Multigraph V E) /-- **Independent sets count edges once.** If no edge has both endpoints in `I`, the edges of a set `X` at the vertices of `I` are the disjoint union of those at each vertex of `I`. -/ -theorem ncard_inter_touching [Finite E] {I : Finset V} (hI : ∀ e, ¬(G.src e ∈ I ∧ G.tgt e ∈ I)) +private theorem ncard_inter_touching [Finite E] {I : Finset V} + (hI : ∀ e, ¬(G.src e ∈ I ∧ G.tgt e ∈ I)) (X : Set E) : (X ∩ G.touching I).ncard = ∑ v ∈ I, (X ∩ G.incidenceSet v).ncard := by classical have := Fintype.ofFinite E @@ -186,7 +187,7 @@ theorem mem_edgeCut_iff_otherEnd {L : Set V} {v : V} {e : E} (he : e ∈ G.incid exact not_congr Iff.comm /-- In an independent set, the other ends of the edges at a vertex lie outside the set. -/ -theorem otherEnd_notMem {I : Finset V} (hI : ∀ e, ¬(G.src e ∈ I ∧ G.tgt e ∈ I)) {v : V} +private theorem otherEnd_notMem {I : Finset V} (hI : ∀ e, ¬(G.src e ∈ I ∧ G.tgt e ∈ I)) {v : V} (hv : v ∈ I) {e : E} (he : e ∈ G.incidenceSet v) : G.otherEnd v e ∉ I := by unfold otherEnd split_ifs with hs @@ -209,7 +210,7 @@ variable {G} /-- **A median minimises the local threshold cuts.** If the neighbours of `v` keep their keys and the new key of `v` is a median of theirs, then at every threshold at most as many edges at `v` cross the new threshold cut as crossed the old one. -/ -theorem ncard_edgeCut_threshold_inter_le [Finite E] {α : Type*} [LinearOrder α] +private theorem ncard_edgeCut_threshold_inter_le [Finite E] {α : Type*} [LinearOrder α] {key key' : V → α} {v : V} (hfix : ∀ e ∈ G.incidenceSet v, key' (G.otherEnd v e) = key (G.otherEnd v e)) (hmed : G.IsMedianAt key v (key' v)) (t : α) : diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/Median.lean b/Complexity/Computability/Circuit/Frontier/Layouts/Median.lean index cb94954ce..fb254b1dc 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/Median.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/Median.lean @@ -111,14 +111,14 @@ namespace IsMedian variable {score : E → α} {v : V} {m : α} /-- Some edge at `v` scores at most a median. -/ -theorem exists_score_le (h : G.IsMedian score v m) : +private theorem exists_score_le (h : G.IsMedian score v m) : ∃ e ∈ G.incidenceSet v, score e ≤ m := by obtain ⟨e, he⟩ := nonempty_of_ncard_ne_zero (s := {e ∈ G.incidenceSet v | score e ≤ m}) (by have := h.1; omega) exact ⟨e, he⟩ /-- Some edge at `v` scores at least a median. -/ -theorem exists_le_score (h : G.IsMedian score v m) : +private theorem exists_le_score (h : G.IsMedian score v m) : ∃ e ∈ G.incidenceSet v, m ≤ score e := by obtain ⟨e, he⟩ := nonempty_of_ncard_ne_zero (s := {e ∈ G.incidenceSet v | m ≤ score e}) (by have := h.2; omega) @@ -127,7 +127,7 @@ theorem exists_le_score (h : G.IsMedian score v m) : variable [Finite E] /-- At a vertex with three edges, at most one edge scores below a median. -/ -theorem eq_of_score_lt (h : G.IsMedian score v m) (hv : (G.incidenceSet v).ncard = 3) +private theorem eq_of_score_lt (h : G.IsMedian score v m) (hv : (G.incidenceSet v).ncard = 3) {e e' : E} (he : e ∈ G.incidenceSet v) (he' : e' ∈ G.incidenceSet v) (hlt : score e < m) (hlt' : score e' < m) : e = e' := by by_contra hne @@ -142,7 +142,7 @@ theorem eq_of_score_lt (h : G.IsMedian score v m) (hv : (G.incidenceSet v).ncard omega /-- At a vertex with three edges, at most one edge scores above a median. -/ -theorem eq_of_lt_score (h : G.IsMedian score v m) (hv : (G.incidenceSet v).ncard = 3) +private theorem eq_of_lt_score (h : G.IsMedian score v m) (hv : (G.incidenceSet v).ncard = 3) {e e' : E} (he : e ∈ G.incidenceSet v) (he' : e' ∈ G.incidenceSet v) (hlt : m < score e) (hlt' : m < score e') : e = e' := by by_contra hne @@ -200,7 +200,7 @@ private theorem ncard_le_add_add (F : Set E) (score : E → α) (t t' : α) : /-- **Charging low edges.** If the medians outside `P` are at least `m`, the edges leaving `P` that score below a threshold `t ≤ m` are no more than the vertices outside `P` that straddle `t`. -/ -theorem ncard_edgeCut_score_lt_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).ncard = 3) +private theorem ncard_edgeCut_score_lt_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).ncard = 3) (hmed : ∀ v, G.IsMedian score v (med v)) (hPc : ∀ v ∉ P, m ≤ med v) {t : α} (ht : t ≤ m) : {e ∈ G.edgeCut P | score e < t}.ncard ≤ {v | v ∉ P ∧ G.EdgeStraddles score t v}.ncard := by @@ -221,7 +221,7 @@ theorem ncard_edgeCut_score_lt_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).nca /-- **Charging high edges.** If the medians inside `P` are at most `m`, the edges leaving `P` that score at least a threshold `t > m` are no more than the vertices inside `P` with an edge scoring at least `t`. -/ -theorem ncard_edgeCut_le_score_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).ncard = 3) +private theorem ncard_edgeCut_le_score_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).ncard = 3) (hmed : ∀ v, G.IsMedian score v (med v)) (hP : ∀ u ∈ P, med u ≤ m) {t : α} (ht : m < t) : {e ∈ G.edgeCut P | t ≤ score e}.ncard ≤ @@ -240,7 +240,7 @@ theorem ncard_edgeCut_le_score_le [Finite V] (h3 : ∀ v, (G.incidenceSet v).nca (((hP _ hu).trans_lt ht).trans_le hle') /-- The endpoints of a set of edges number at most twice the edges. -/ -theorem ncard_endpoints_le (F : Set E) : +private theorem ncard_endpoints_le (F : Set E) : {w | ∃ e ∈ F, G.src e = w ∨ G.tgt e = w}.ncard ≤ 2 * F.ncard := by refine (ncard_le_ncard (t := G.src '' F ∪ G.tgt '' F) ?_).trans ((ncard_union_le _ _).trans ?_) diff --git a/Complexity/Computability/Circuit/Frontier/Layouts/VertexGaussian.lean b/Complexity/Computability/Circuit/Frontier/Layouts/VertexGaussian.lean index f7c8aa4d9..7593cc86f 100644 --- a/Complexity/Computability/Circuit/Frontier/Layouts/VertexGaussian.lean +++ b/Complexity/Computability/Circuit/Frontier/Layouts/VertexGaussian.lean @@ -83,7 +83,7 @@ def crossingEvent (q : ℝ) (R : ℕ) (t : ℝ) (e : E) : Set (V → ℝ) := variable {G} {q : ℝ} {R : ℕ} -theorem measurable_vertexScore (q : ℝ) (R : ℕ) (v : V) : +private theorem measurable_vertexScore (q : ℝ) (R : ℕ) (v : V) : Measurable fun ω => vertexScore G q R ω v := by unfold vertexScore fun_prop diff --git a/Complexity/Computability/Circuit/Frontier/Ledger/Basic.lean b/Complexity/Computability/Circuit/Frontier/Ledger/Basic.lean index 47ca18c8d..0f08eaee6 100644 --- a/Complexity/Computability/Circuit/Frontier/Ledger/Basic.lean +++ b/Complexity/Computability/Circuit/Frontier/Ledger/Basic.lean @@ -105,7 +105,7 @@ def run (m : M) (x : Fin n → U) : Wire n s → U := /-- The value of a gate in the run with guess `m`: the readout for a special gate, and the gate applied to the values of its arguments otherwise. -/ -theorem run_gate (m : M) (x : Fin n → U) (g : Fin s) : +private theorem run_gate (m : M) (x : Fin n → U) (g : Fin s) : L.run m x (.gate g) = if h : special g then L.readout m ⟨g, h⟩ else I (p.lines g).op fun a => L.run m x ((p.lines g).wires a) := p.trace_eraseGates_gate x g diff --git a/Complexity/Computability/Circuit/Frontier/Ledger/Sweep.lean b/Complexity/Computability/Circuit/Frontier/Ledger/Sweep.lean index bf6d1397b..674234236 100644 --- a/Complexity/Computability/Circuit/Frontier/Ledger/Sweep.lean +++ b/Complexity/Computability/Circuit/Frontier/Ledger/Sweep.lean @@ -104,14 +104,14 @@ noncomputable def liveNetwork (U : Type*) : variable {p special} /-- The live wires are signals of the live circuit. -/ -theorem reach_of_live {w : Wire n s} (hw : Live p special w) : +private theorem reach_of_live {w : Wire n s} (hw : Live p special w) : Compiler.Reach (liveCircuit p special) w := by have h := Compiler.Reach.output (c := liveCircuit p special) (Finite.equivFin {w // Live p special w} ⟨w, hw⟩) simpa [liveCircuit] using h /-- The inputs are signals of the live circuit. -/ -theorem reach_input (i : Fin n) : Compiler.Reach (liveCircuit p special) (.input i) := +private theorem reach_input (i : Fin n) : Compiler.Reach (liveCircuit p special) (.input i) := reach_of_live trivial /-- The inner gates of the live circuit are the ordinary inner gates. -/ @@ -134,7 +134,7 @@ theorem card_live_le : rw [Nat.card_sum, Nat.card_eq_fintype_card (α := Fin n), Fintype.card_fin] /-- The live network reads every input. -/ -theorem read_liveNetwork : (liveNetwork p special U).read = univ := +private theorem read_liveNetwork : (liveNetwork p special U).read = univ := eq_univ_of_forall fun i => ⟨_, mem_univ _, Compiler.site_of_reach (reach_input i)⟩ /-- When there are inputs, the graph of the live circuit has a vertex. -/ @@ -161,19 +161,20 @@ noncomputable abbrev network (m : M) : Compiler.network (liveCircuit p special) (I.withConstants (L.readout m)) fun _ => univ /-- The run with guess `m` satisfies the network on the guess `m`. -/ -theorem satisfies_network (m : M) (x : Fin n → U) : +private theorem satisfies_network (m : M) (x : Fin n → U) : (L.network m).Satisfies x fun e => L.run m x e.signal.1 := Compiler.satisfies_trace fun _ => mem_univ _ /-- A satisfying assignment of the network on the guess `m` is the run with guess `m`. -/ -theorem eq_run_of_satisfies {m : M} {x : Fin n → U} {α : Compiler.Edge (liveCircuit p special) → U} +private theorem eq_run_of_satisfies {m : M} {x : Fin n → U} + {α : Compiler.Edge (liveCircuit p special) → U} (h : (L.network m).Satisfies x α) (e : Compiler.Edge (liveCircuit p special)) : α e = L.run m x e.signal.1 := Compiler.eq_trace h e /-- A wire that is not a signal of the live circuit is a constant of the erased program, so its value in a run depends only on the guess. -/ -theorem run_eq_of_not_reach (m : M) {w : Wire n s} +private theorem run_eq_of_not_reach (m : M) {w : Wire n s} (hw : ¬Compiler.Reach (liveCircuit p special) w) (x y : Fin n → U) : L.run m x w = L.run m y w := by have hlive : ¬Live p special w := fun h => hw (reach_of_live h) @@ -347,7 +348,7 @@ theorem ncard_transition_le_readIn [Finite U] [Finite M] {t : ℕ} /-- At the last step the transition is determined by the guess and the two ledgers, since every input is read. -/ -theorem ncard_transition_last_le [Finite U] [Finite M] : +private theorem ncard_transition_last_le [Finite U] [Finite M] : ((L.sweep o Acc π).transition (Nat.card (Compiler.Vertex (liveCircuit p special))) '' {x | p.trace I x o ∈ Acc}).ncard ≤ Nat.card M ^ 3 := by have h : ((L.sweep o Acc π).transition (Nat.card (Compiler.Vertex (liveCircuit p special))) '' diff --git a/Complexity/Computability/Circuit/Frontier/Linear/LowerBound.lean b/Complexity/Computability/Circuit/Frontier/Linear/LowerBound.lean index 32ff10986..080e09f7a 100644 --- a/Complexity/Computability/Circuit/Frontier/Linear/LowerBound.lean +++ b/Complexity/Computability/Circuit/Frontier/Linear/LowerBound.lean @@ -140,7 +140,7 @@ private theorem eval_eq_mulVec (hc : c.Computes I fun x => M *ᵥ x) (x : Fin N /-- **Every output of a totally regular map depends on every input**, so in the graph of a circuit computing it the vertex of every input is joined to every output vertex. -/ -theorem exists_reachable_of_isTotallyRegular (hM : M.IsTotallyRegular) +private theorem exists_reachable_of_isTotallyRegular (hM : M.IsTotallyRegular) (hc : c.Computes I fun x => M *ᵥ x) (i o : Fin N) : ∃ hi : Reach c (.input i), (graph c).toSimpleGraph.Reachable (.signal ⟨.input i, hi⟩) (.output o) := by @@ -152,14 +152,14 @@ theorem exists_reachable_of_isTotallyRegular (hM : M.IsTotallyRegular) /-- The graph of a circuit computing a totally regular map with at least one input is connected. -/ -theorem connected_of_isTotallyRegular (hN : 0 < N) (hM : M.IsTotallyRegular) +private theorem connected_of_isTotallyRegular (hN : 0 < N) (hM : M.IsTotallyRegular) (hc : c.Computes I fun x => M *ᵥ x) : (graph c).toSimpleGraph.Connected := by obtain ⟨hi, -⟩ := exists_reachable_of_isTotallyRegular hM hc ⟨0, hN⟩ ⟨0, hN⟩ exact connected_of_reachable (v₀ := .signal ⟨.input ⟨0, hN⟩, hi⟩) fun o => (exists_reachable_of_isTotallyRegular hM hc ⟨0, hN⟩ o).2 /-- A circuit computing a totally regular map reads all of its inputs. -/ -theorem read_eq_univ_of_isTotallyRegular (hM : M.IsTotallyRegular) +private theorem read_eq_univ_of_isTotallyRegular (hM : M.IsTotallyRegular) (hc : c.Computes I fun x => M *ᵥ x) (Acc : Fin N → Set F) : (network c I Acc).read = univ := by rw [read_network] @@ -269,7 +269,8 @@ theorem exists_injective_frontier (hM : M.IsTotallyRegular) (hc : c.Computes I f /-- **Every layout is wide.** Every layout of the graph of a circuit with linear capacity computing a totally regular map `F^N → F^N` has width at least `N`. -/ -theorem le_width_of_isTotallyRegular (hM : M.IsTotallyRegular) (hc : c.Computes I fun x => M *ᵥ x) +private theorem le_width_of_isTotallyRegular (hM : M.IsTotallyRegular) + (hc : c.Computes I fun x => M *ᵥ x) (hcap : c.LinearCapacity I) (π : Layout (Vertex c)) : N ≤ (graph c).width π := by obtain ⟨t, ht⟩ := exists_injective_frontier hM hc π -- The wires carried by the frontier. diff --git a/Complexity/Computability/Circuit/Frontier/LowerBound.lean b/Complexity/Computability/Circuit/Frontier/LowerBound.lean index 7e46f3038..8a3597da4 100644 --- a/Complexity/Computability/Circuit/Frontier/LowerBound.lean +++ b/Complexity/Computability/Circuit/Frontier/LowerBound.lean @@ -66,7 +66,7 @@ universe u v variable {U : Type u} [Finite U] [Nontrivial U] /-- A set of inputs has at most `|U| ^ n` elements: `log_|U| |S| ≤ n`. -/ -theorem logb_ncard_le_self {n : ℕ} {S : Set (Fin n → U)} (hS : S.Nonempty) : +private theorem logb_ncard_le_self {n : ℕ} {S : Set (Fin n → U)} (hS : S.Nonempty) : Real.logb (Nat.card U) S.ncard ≤ n := by have hq : (1 : ℝ) < Nat.card U := by exact_mod_cast Finite.one_lt_card have hle : (S.ncard : ℝ) ≤ (Nat.card U : ℝ) ^ n := by @@ -81,7 +81,7 @@ theorem logb_ncard_le_self {n : ℕ} {S : Set (Fin n → U)} (hS : S.Nonempty) : variable {S : ∀ n, Set (Fin n → U)} {K : ℕ → ℕ} /-- A dense family of sets has `n - log_|U| |S_n| = o(n)`. -/ -theorem isLittleO_sub_logb_ncard +private theorem isLittleO_sub_logb_ncard (hdense : (fun n => n * Real.log (Nat.card U) - Real.log (S n).ncard) =o[atTop] fun n => (n : ℝ)) : (fun n : ℕ => (n : ℝ) - Real.logb (Nat.card U) (S n).ncard) =o[atTop] fun n => (n : ℝ) := by diff --git a/Complexity/Computability/Circuit/Frontier/Multigraph.lean b/Complexity/Computability/Circuit/Frontier/Multigraph.lean index 0961d2873..912ea4ecb 100644 --- a/Complexity/Computability/Circuit/Frontier/Multigraph.lean +++ b/Complexity/Computability/Circuit/Frontier/Multigraph.lean @@ -293,7 +293,7 @@ theorem edgeCut_union_of_edgeCut_eq_empty {K L : Set V} (hK : G.edgeCut K = ∅) · simp [mem_edgeCut, hs, mt hKe.2 hs] /-- The edges touching a closed set `W` are those with both endpoints in `W`. -/ -theorem touching_eq_of_edgeCut_eq_empty {W : Set V} (hW : G.edgeCut W = ∅) : +private theorem touching_eq_of_edgeCut_eq_empty {W : Set V} (hW : G.edgeCut W = ∅) : G.touching W = {e | G.src e ∈ W ∧ G.tgt e ∈ W} := by ext e have := G.edgeCut_eq_empty_iff.1 hW e @@ -303,7 +303,7 @@ theorem touching_eq_of_edgeCut_eq_empty {W : Set V} (hW : G.edgeCut W = ∅) : /-! ### Connected components -/ /-- The endpoints of an edge lie in the same connected component. -/ -theorem connectedComponentMk_src (e : E) : +private theorem connectedComponentMk_src (e : E) : G.toSimpleGraph.connectedComponentMk (G.src e) = G.toSimpleGraph.connectedComponentMk (G.tgt e) := SimpleGraph.ConnectedComponent.sound (G.reachable_src_tgt e) @@ -352,7 +352,7 @@ theorem MaxDegreeLE.induce [Finite E] {d : ℕ} (hG : G.MaxDegreeLE d) (W : Set Subtype.val_injective.injOn).trans (hG w) /-- The simple graph underlying an induced subgraph is the induced simple graph. -/ -theorem toSimpleGraph_induce (W : Set V) : +private theorem toSimpleGraph_induce (W : Set V) : (G.induce W).toSimpleGraph = G.toSimpleGraph.induce W := by ext u v simp only [toSimpleGraph_adj, SimpleGraph.comap_adj, Function.Embedding.subtype_apply, ne_eq, diff --git a/Complexity/Computability/Circuit/Frontier/Network.lean b/Complexity/Computability/Circuit/Frontier/Network.lean index f966cd20d..995686f68 100644 --- a/Complexity/Computability/Circuit/Frontier/Network.lean +++ b/Complexity/Computability/Circuit/Frontier/Network.lean @@ -196,7 +196,7 @@ theorem frontierValues_of_mem {t : ℕ} {α : E → U} {e : E} (he : e ∈ N.fro N.frontierValues π t α e = some (α e) := by simp [frontierValues, he] -theorem frontierValues_of_notMem {t : ℕ} {α : E → U} {e : E} (he : e ∉ N.frontier π t) : +private theorem frontierValues_of_notMem {t : ℕ} {α : E → U} {e : E} (he : e ∉ N.frontier π t) : N.frontierValues π t α e = none := by simp [frontierValues, he] @@ -225,7 +225,7 @@ theorem revealedBy_mono : Monotone (N.revealedBy π) := by /-- The inputs revealed while processing the vertex numbered `t` are those read at that vertex. -/ -theorem revealedBy_succ_diff {t : ℕ} (ht : t < Nat.card V) : +private theorem revealedBy_succ_diff {t : ℕ} (ht : t < Nat.card V) : N.revealedBy π (t + 1) \ N.revealedBy π t = N.readAt (π.symm ⟨t, ht⟩) := by ext i simp only [revealedBy, show t + 1 ≤ Nat.card V by omega, ht.le, ite_true, mem_sdiff, readIn, @@ -250,7 +250,7 @@ theorem revealedBy_succ_diff_subset {t : ℕ} (ht : t < Nat.card V) : (N.revealedBy_succ_diff π ht).subset /-- After the last vertex, the inputs revealed are those the network does not read. -/ -theorem revealedBy_card_succ_diff : +private theorem revealedBy_card_succ_diff : N.revealedBy π (Nat.card V + 1) \ N.revealedBy π (Nat.card V) = N.readᶜ := by simp [revealedBy, read, π.initial_of_card_le le_rfl, compl_eq_univ_sdiff] @@ -305,19 +305,19 @@ theorem branchingProgram_edge_iff {t : ℕ} {m m' : E → Option U} Iff.rfl /-- The step processing the vertex numbered `t` reads the inputs read at that vertex. -/ -theorem newly_branchingProgram {t : ℕ} (ht : t < Nat.card V) : +private theorem newly_branchingProgram {t : ℕ} (ht : t < Nat.card V) : (N.branchingProgram π).newly t = N.readAt (π.symm ⟨t, ht⟩) := N.revealedBy_succ_diff π ht /-- The last step reads the inputs that the network does not read. -/ -theorem newly_branchingProgram_card : +private theorem newly_branchingProgram_card : (N.branchingProgram π).newly (Nat.card V) = N.readᶜ := N.revealedBy_card_succ_diff π /-! #### Exactness -/ /-- The frontier values of a satisfying assignment form an accepting path. -/ -theorem isAcceptingPath_frontierValues {x : ι → U} {α : E → U} (hα : N.Satisfies x α) : +private theorem isAcceptingPath_frontierValues {x : ι → U} {α : E → U} (hα : N.Satisfies x α) : (N.branchingProgram π).IsAcceptingPath x fun t => N.frontierValues π t α where start := funext fun _ => N.frontierValues_of_notMem π (by simp) accept := funext fun _ => N.frontierValues_of_notMem π <| by @@ -420,7 +420,7 @@ theorem unambiguous_branchingProgram /-- **Edges by width.** At a step that processes a vertex, an edge of the program is determined by the values of an assignment on the two frontiers and the inputs read at the vertex. -/ -theorem ncard_edges_le [Finite ι] [Finite U] [Finite E] {t : ℕ} (ht : t < Nat.card V) : +private theorem ncard_edges_le [Finite ι] [Finite U] [Finite E] {t : ℕ} (ht : t < Nat.card V) : ((N.branchingProgram π).edges t).ncard ≤ Nat.card U ^ ((N.frontier π t ∪ N.frontier π (t + 1)).ncard + (N.readAt (π.symm ⟨t, ht⟩)).ncard) := by @@ -446,7 +446,7 @@ theorem ncard_edges_le [Finite ι] [Finite U] [Finite E] {t : ℕ} (ht : t < Nat /-- At the last step both frontiers are empty, so an edge of the program is determined by the unread inputs. -/ -theorem ncard_edges_last_le [Finite ι] [Finite U] : +private theorem ncard_edges_last_le [Finite ι] [Finite U] : ((N.branchingProgram π).edges (Nat.card V)).ncard ≤ Nat.card U ^ N.readᶜ.ncard := by have hempty (s : ℕ) (hs : Nat.card V ≤ s) (α : E → U) : N.frontierValues π s α = fun _ => none := by diff --git a/Complexity/Computability/Circuit/Frontier/Nondeterministic.lean b/Complexity/Computability/Circuit/Frontier/Nondeterministic.lean index 1420f4b77..a8b483078 100644 --- a/Complexity/Computability/Circuit/Frontier/Nondeterministic.lean +++ b/Complexity/Computability/Circuit/Frontier/Nondeterministic.lean @@ -112,20 +112,20 @@ theorem accepted_hiddenNetwork [Nonempty U] : rw [happend] /-- Each vertex of the hidden network reads at most one input. -/ -theorem ncard_readAt_hiddenNetwork_le (v : Vertex c) : +private theorem ncard_readAt_hiddenNetwork_le (v : Vertex c) : ((hiddenNetwork c I Acc).readAt v).ncard ≤ 1 := (Network.ncard_readAt_hide_le _ v).trans ((Network.ncard_readAt_reindex _ _ v).trans_le (ncard_readAt_le I Acc v)) /-- The hidden network reads no more inputs than the network of the circuit. -/ -theorem ncard_read_hiddenNetwork_le : +private theorem ncard_read_hiddenNetwork_le : (hiddenNetwork c I Acc).read.ncard ≤ (network c I Acc).read.ncard := (Network.ncard_read_hide_le _).trans (Network.ncard_read_reindex _ _).le /-- **The cycle rank.** For fan-in at most `r`, if the graph of the circuit is connected, its cycle rank and the number of ordinary inputs read by the hidden network add up to at most `(r - 1) s + 1`, where `s` counts the inner gates. -/ -theorem cycleRank_add_ncard_read_hiddenNetwork_le {r : ℕ} (hfan : c.FanInAtMost r) +private theorem cycleRank_add_ncard_read_hiddenNetwork_le {r : ℕ} (hfan : c.FanInAtMost r) (hconn : (graph c).toSimpleGraph.Connected) : (graph c).cycleRank + (hiddenNetwork c I Acc).read.ncard ≤ (r - 1) * c.innerSize + 1 := (Nat.add_le_add_left (ncard_read_hiddenNetwork_le c I Acc) _).trans @@ -141,7 +141,7 @@ variable {I : Interpretation σ U} {Acc : Set U} {c : Circuit σ (n + k) 1} {S : {K r : ℕ} /-- The hidden network of a circuit deciding `S` nondeterministically accepts exactly `S`. -/ -theorem accepted_hiddenNetwork_of_nondeterministicDecides [Nonempty U] +private theorem accepted_hiddenNetwork_of_nondeterministicDecides [Nonempty U] (hS : c.NondeterministicDecides I Acc S) : (Compiler.hiddenNetwork c I fun _ => Acc).accepted = S := by rw [Compiler.accepted_hiddenNetwork] @@ -154,7 +154,7 @@ variable [Finite U] [Nontrivial U] /-- **The cycle rank of the graph of a nondeterministic circuit** deciding a large `K`-rectangle-free set `S ⊆ U^n` is at most `(r - 1) s - n + log_q K + 1` for fan-in at most `r`, where `s` counts the inner gates. Only the `n` ordinary inputs are subtracted. -/ -theorem cycleRank_le_of_nondeterministicDecides (hfan : c.FanInAtMost r) +private theorem cycleRank_le_of_nondeterministicDecides (hfan : c.FanInAtMost r) (hS : c.NondeterministicDecides I Acc S) (hfree : RectangleFree S K) (hbig : Nat.card U * K ^ 2 ≤ S.ncard) : ((Compiler.graph c).cycleRank : ℝ) ≤ @@ -182,7 +182,7 @@ theorem cycleRank_le_of_nondeterministicDecides (hfan : c.FanInAtMost r) /-- **Every layout of the graph of a nondeterministic circuit is wide.** For a circuit of fan-in at most `r ≥ 2` deciding a large `K`-rectangle-free set `S` nondeterministically, every layout `π` of its graph satisfies `log_q |S| ≤ width π + (r + 2) + 3 log_q K + log_q (|V| + 1)`. -/ -theorem logb_ncard_le_width_of_nondeterministicDecides (hr : 2 ≤ r) (hfan : c.FanInAtMost r) +private theorem logb_ncard_le_width_of_nondeterministicDecides (hr : 2 ≤ r) (hfan : c.FanInAtMost r) (hS : c.NondeterministicDecides I Acc S) (hfree : RectangleFree S K) (hbig : Nat.card U * K ^ 2 ≤ S.ncard) (π : Layout (Compiler.Vertex c)) : Real.logb (Nat.card U) S.ncard ≤ @@ -264,7 +264,7 @@ hypothesis for subcubic graphs with coefficient `A > 0`. Under the hypotheses of every circuit of fan-in at most two with any number of witness inputs deciding `S_n` nondeterministically, over any basis and interpretation on `U`, has more than `(1 + 1/A - ε) n` inner gates. -/ -theorem eventually_lt_innerSize_of_nondeterministicDecides {A : ℝ} (hA : 0 < A) +private theorem eventually_lt_innerSize_of_nondeterministicDecides {A : ℝ} (hA : 0 < A) (hlayout : LayoutBound 3 A) (hfree : ∀ᶠ n in atTop, RectangleFree (S n) (K n)) (hK : (fun n => Real.log (K n)) =o[atTop] fun n => (n : ℝ)) (hdense : (fun n => n * Real.log (Nat.card U) - Real.log (S n).ncard) =o[atTop] diff --git a/Complexity/Computability/Circuit/Frontier/Projection.lean b/Complexity/Computability/Circuit/Frontier/Projection.lean index 3fd1e223e..e78b1d64d 100644 --- a/Complexity/Computability/Circuit/Frontier/Projection.lean +++ b/Complexity/Computability/Circuit/Frontier/Projection.lean @@ -72,11 +72,11 @@ theorem satisfies_reindex_iff {x : ι' → U} {α : E → U} : theorem accepted_reindex : (N.reindex e).accepted = {x | x ∘ e ∈ N.accepted} := rfl -theorem readAt_reindex (v : V) : (N.reindex e).readAt v = e '' N.readAt v := by +private theorem readAt_reindex (v : V) : (N.reindex e).readAt v = e '' N.readAt v := by rw [e.image_eq_preimage_symm] rfl -theorem read_reindex : (N.reindex e).read = e '' N.read := by +private theorem read_reindex : (N.reindex e).read = e '' N.read := by rw [e.image_eq_preimage_symm] rfl diff --git a/Complexity/Computability/Circuit/Frontier/Rectangle.lean b/Complexity/Computability/Circuit/Frontier/Rectangle.lean index de9c97653..9fba71c6e 100644 --- a/Complexity/Computability/Circuit/Frontier/Rectangle.lean +++ b/Complexity/Computability/Circuit/Frontier/Rectangle.lean @@ -290,7 +290,7 @@ theorem signedCount_eq_add_sdiff (S : Set (ι → U)) {R D : Set (ι → U)} (h ring /-- The signed count is twice the deviation of `|R ∩ S|` from `|R| / 2`. -/ -theorem signedCount_eq_two_mul (S R : Set (ι → U)) : +private theorem signedCount_eq_two_mul (S R : Set (ι → U)) : signedCount S R = 2 * (((R ∩ S).ncard : ℝ) - R.ncard / 2) := by have : ((R ∩ S).ncard : ℝ) + (R \ S).ncard = R.ncard := by exact_mod_cast ncard_inter_add_ncard_sdiff_eq_ncard R S diff --git a/Complexity/Computability/Circuit/Frontier/Sweep.lean b/Complexity/Computability/Circuit/Frontier/Sweep.lean index b2b75c70e..2c070ccc1 100644 --- a/Complexity/Computability/Circuit/Frontier/Sweep.lean +++ b/Complexity/Computability/Circuit/Frontier/Sweep.lean @@ -156,14 +156,14 @@ theorem one_le_ncard_futureSide [Finite ι] [Finite U] {x : ι → U} (hx : x (ncard_pos (toFinite _)).mpr ⟨_, x, ⟨hx, rfl⟩, rfl⟩ /-- At the start nothing is revealed, so there is at most one revealed part. -/ -theorem ncard_pastSide_zero_le (x : ι → U) : (P.pastSide 0 x).ncard ≤ 1 := by +private theorem ncard_pastSide_zero_le (x : ι → U) : (P.pastSide 0 x).ncard ≤ 1 := by have : Subsingleton (P.revealed 0 → U) := ⟨fun a b => funext fun i => absurd i.2 (by simp [P.revealed_zero])⟩ exact (ncard_le_one (toFinite _)).mpr fun a _ b _ => Subsingleton.elim a b /-- At the end everything is revealed and every input of `S` is a peer, so the revealed parts are as numerous as `S`. -/ -theorem ncard_pastSide_length {x : ι → U} (hx : x ∈ S) : +private theorem ncard_pastSide_length {x : ι → U} (hx : x ∈ S) : (P.pastSide P.length x).ncard = S.ncard := by have hpeers : P.peers P.length x = S := subset_antisymm (fun _ hy => hy.1) fun y hy => ⟨hy, P.message_length y hy x hx⟩ @@ -173,7 +173,7 @@ theorem ncard_pastSide_length {x : ι → U} (hx : x ∈ S) : /-- The time at which `x` is charged: the first time its peers have at least `K` distinct revealed parts. -/ -noncomputable def chargeTime (K : ℕ) (x : ι → U) : ℕ := +private noncomputable def chargeTime (K : ℕ) (x : ι → U) : ℕ := sInf {t | K ≤ (P.pastSide t x).ncard} /-- **The charging argument.** If at every time up to the end each input of `S` has fewer than diff --git a/Complexity/Computability/Circuit/Fusion/Basic.lean b/Complexity/Computability/Circuit/Fusion/Basic.lean index e6408cb11..790186c0c 100644 --- a/Complexity/Computability/Circuit/Fusion/Basic.lean +++ b/Complexity/Computability/Circuit/Fusion/Basic.lean @@ -140,7 +140,7 @@ def Cover.ofProgram (p : Program σ n g) (I : Interpretation σ U) (P : W → U (p.cost_eq_sum weight).symm /-- Every program violating all candidate invariants pays at least the minimum cover cost. -/ -theorem coverComplexity_le_program_cost (p : Program σ n g) (I : Interpretation σ U) +private theorem coverComplexity_le_program_cost (p : Program σ n g) (I : Interpretation σ U) (P : W → U → Prop) (input : Fin n → U) (hin : ∀ t i, P t (input i)) (hfail : ∀ t, ∃ w, ¬ P t (p.trace I input w)) (weight : σ.Op → ℕ) : coverComplexity I P weight ≤ p.cost weight := by diff --git a/Complexity/Computability/Circuit/Fusion/Converse.lean b/Complexity/Computability/Circuit/Fusion/Converse.lean index 28a904c27..34ac03c0a 100644 --- a/Complexity/Computability/Circuit/Fusion/Converse.lean +++ b/Complexity/Computability/Circuit/Fusion/Converse.lean @@ -106,7 +106,8 @@ theorem PairCover.exists_forallGuess {n : ℕ} (f : BooleanFunction n) exact Formula.eval_toCircuit _ _ _ _ /-- The semi-ultrafilter bound applies after minimizing over all auxiliary counts and verifiers. -/ -theorem pairCoverComplexity_le_econondeterministicAndComplexity {n : ℕ} (f : BooleanFunction n) : +private theorem pairCoverComplexity_le_econondeterministicAndComplexity {n : ℕ} + (f : BooleanFunction n) : pairCoverComplexity {x | f x = true} (fun i => {x | AltFormula.literals x i = true}) Semifilter.IsUltra ≤ econondeterministicAndComplexity f := by apply le_econondeterministicAndComplexity_iff.mpr @@ -115,7 +116,8 @@ theorem pairCoverComplexity_le_econondeterministicAndComplexity {n : ℕ} (f : B exact pairCoverComplexity_forallGuess_le_cost g c hc /-- A semi-ultrafilter cover gives a universal verifier at most five times as costly. -/ -theorem econondeterministicAndComplexity_le_pairCoverComplexity {n : ℕ} (f : BooleanFunction n) : +private theorem econondeterministicAndComplexity_le_pairCoverComplexity {n : ℕ} + (f : BooleanFunction n) : econondeterministicAndComplexity f ≤ 5 * pairCoverComplexity {x | f x = true} (fun i => {x | AltFormula.literals x i = true}) Semifilter.IsUltra := by diff --git a/Complexity/Computability/Circuit/Fusion/Counting.lean b/Complexity/Computability/Circuit/Fusion/Counting.lean index d78078715..357c9eddb 100644 --- a/Complexity/Computability/Circuit/Fusion/Counting.lean +++ b/Complexity/Computability/Circuit/Fusion/Counting.lean @@ -55,7 +55,7 @@ noncomputable def Atom.failures (a : Atom σ U) (I : Interpretation σ U) simp only [failures, Finset.mem_filter] /-- The sampled witnesses are covered by the union of the atoms' failures. -/ -theorem card_le_sum_failures (atoms : Fin k → Atom σ U) (samples : Finset W) +private theorem card_le_sum_failures (atoms : Fin k → Atom σ U) (samples : Finset W) (hcover : ∀ t ∈ samples, ¬ ∀ i, (atoms i).Preserves I (P t)) : samples.card ≤ ∑ i, ((atoms i).failures I P samples).card := by classical diff --git a/Complexity/Computability/Circuit/Fusion/Cyclic.lean b/Complexity/Computability/Circuit/Fusion/Cyclic.lean index 8c236d47c..c2b85ab75 100644 --- a/Complexity/Computability/Circuit/Fusion/Cyclic.lean +++ b/Complexity/Computability/Circuit/Fusion/Cyclic.lean @@ -112,7 +112,7 @@ theorem pairCover_lowerBound_cyclic {target : Set U} {input : Fin n → Set U} hbound (PairCover.ofCyclicCircuit c input o hc admissible) /-- The minimum pair-cover length bounds the AND cost of any cyclic construction. -/ -theorem pairCoverComplexity_le_cyclic_cost {target : Set U} +private theorem pairCoverComplexity_le_cyclic_cost {target : Set U} (c : CyclicCircuit Monotone.signature n m) (input : Fin n → Set U) (o : Fin m) (hc : c.eval (Monotone.setInterpretation U) Monotone.setInterpretation_mono input o = target) (admissible : Semifilter ↥(targetᶜ) → Prop := fun _ => True) : diff --git a/Complexity/Computability/Circuit/Fusion/Cyclic/Closure.lean b/Complexity/Computability/Circuit/Fusion/Cyclic/Closure.lean index a58d735de..0ecd83aec 100644 --- a/Complexity/Computability/Circuit/Fusion/Cyclic/Closure.lean +++ b/Complexity/Computability/Circuit/Fusion/Cyclic/Closure.lean @@ -103,7 +103,7 @@ theorem PairDerivation.mem_of_outside (x : ↥(targetᶜ)) (fun _ _ hst hx => hst hx) (fun _ _ hx hy => ⟨hx, hy⟩) s h /-- An unrestricted cover forces the empty set at each target point. -/ -theorem PairCover.derives_empty (c : PairCover target input) (hpoint : point ∈ target) : +private theorem PairCover.derives_empty (c : PairCover target input) (hpoint : point ∈ target) : PairDerivation target input c.pairs point ∅ := by by_contra h apply c.isCover ⟨⟨point, hpoint⟩, PairDerivation.semifilter h, trivial, .input⟩ diff --git a/Complexity/Computability/Circuit/Fusion/Cyclic/Compiler.lean b/Complexity/Computability/Circuit/Fusion/Cyclic/Compiler.lean index b89e71a50..b2e1ca198 100644 --- a/Complexity/Computability/Circuit/Fusion/Cyclic/Compiler.lean +++ b/Complexity/Computability/Circuit/Fusion/Cyclic/Compiler.lean @@ -111,7 +111,7 @@ def joinFormula {r : ℕ} (seed : Bool) : List (Formula Monotone.signature r) | f :: fs => Monotone.or f (joinFormula seed fs) /-- The union tree charges exactly the conjunctions in its arguments. -/ -theorem cost_joinFormula {r : ℕ} (seed : Bool) (fs : List (Formula Monotone.signature r)) : +private theorem cost_joinFormula {r : ℕ} (seed : Bool) (fs : List (Formula Monotone.signature r)) : (joinFormula seed fs).cost Monotone.andCost = (fs.map (·.cost Monotone.andCost)).sum := by induction fs with | nil => simp [joinFormula, Monotone.const] @@ -128,7 +128,8 @@ theorem mem_eval_joinFormula {r : ℕ} (seed : Bool) (fs : List (Formula Monoton simp [joinFormula, Monotone.or, ih, or_left_comm] /-- Every union tree has an operation at its root, including the empty tree. -/ -theorem joinFormula_isGate {r : ℕ} (seed : Bool) (fs : List (Formula Monotone.signature r)) : +private theorem joinFormula_isGate {r : ℕ} (seed : Bool) + (fs : List (Formula Monotone.signature r)) : ∃ op args, joinFormula seed fs = .gate op args := by cases fs <;> exact ⟨_, _, rfl⟩ diff --git a/Complexity/Computability/Circuit/Fusion/DeMorgan.lean b/Complexity/Computability/Circuit/Fusion/DeMorgan.lean index ff2de2cf4..00333789a 100644 --- a/Complexity/Computability/Circuit/Fusion/DeMorgan.lean +++ b/Complexity/Computability/Circuit/Fusion/DeMorgan.lean @@ -82,7 +82,7 @@ def railSelect (k : Fin (2 * n + 1)) : Fin (n + n + 1) := else Fin.castAdd 1 (Fin.natAdd n ⟨(k.val - 1) / 2, by have := k.isLt; omega⟩) /-- The dual-rail inputs are a selection from the literals and the constant `true`. -/ -theorem railBitString_eq_append_literals (x : BitString n) (k : Fin (2 * n + 1)) : +private theorem railBitString_eq_append_literals (x : BitString n) (k : Fin (2 * n + 1)) : railBitString x k = Fin.append (Boolean.AltFormula.literals x) (fun _ : Fin 1 => true) (railSelect k) := by have hlen : (List.ofFn x).length = n := List.length_ofFn @@ -134,7 +134,7 @@ variable {n : ℕ} open Boolean in /-- An unrestricted cover compiles to a monotone circuit computing `f` from its literals. -/ -theorem PairCover.computesFrom_toCircuit {f : BooleanFunction n} +private theorem PairCover.computesFrom_toCircuit {f : BooleanFunction n} (c : PairCover {x | f x = true} (fun i => {x | AltFormula.literals x i = true})) : c.toCircuit.ComputesFrom Monotone.interpretation (fun x (_ : Fin 1) => f x) AltFormula.literals := diff --git a/Complexity/Computability/Circuit/Fusion/Encoding.lean b/Complexity/Computability/Circuit/Fusion/Encoding.lean index c19c5da97..9c107554f 100644 --- a/Complexity/Computability/Circuit/Fusion/Encoding.lean +++ b/Complexity/Computability/Circuit/Fusion/Encoding.lean @@ -66,7 +66,8 @@ def decode (code : CoverCode n t) (input : Fin n → Set U) : Set U := code.read input (code.stages input t) (Fin.last (t + t)) /-- The description has exactly `(2*t+1)*(n+t+1)` independent bits. -/ -theorem card (n t : ℕ) : Fintype.card (CoverCode n t) = 2 ^ ((2 * t + 1) * (n + t + 1)) := by +private theorem card (n t : ℕ) : + Fintype.card (CoverCode n t) = 2 ^ ((2 * t + 1) * (n + t + 1)) := by simp only [CoverCode, Fintype.card_fun, Fintype.card_prod, Fintype.card_bool, Fintype.card_fin] rw [← pow_add, ← pow_succ', ← pow_mul] congr 1 @@ -92,7 +93,7 @@ noncomputable def encode : CoverCode n pairs.length := (fun j => decide ((pairs.get j).1 ∩ (pairs.get j).2 ⊆ coordinate target pairs i))⟩ /-- Encoded reads are the original compiler's reconstructed closure coordinates. -/ -theorem read_encode (state : Fin pairs.length → Set U) +private theorem read_encode (state : Fin pairs.length → Set U) (i : Fin (pairs.length + pairs.length + 1)) : (encode target input pairs).read input state i = readState target input pairs state (coordinate target pairs i) := by @@ -102,7 +103,7 @@ theorem read_encode (state : Fin pairs.length → Set U) simp only [encode, decide_eq_true_eq] /-- Encoded propagation agrees with the original compiler at every stage. -/ -theorem stages_encode (k : ℕ) : +private theorem stages_encode (k : ℕ) : (encode target input pairs).stages input k = stages target input pairs k := by induction k with | zero => rfl diff --git a/Complexity/Computability/Circuit/Fusion/Graph.lean b/Complexity/Computability/Circuit/Fusion/Graph.lean index a27cf700f..99bfa56e4 100644 --- a/Complexity/Computability/Circuit/Fusion/Graph.lean +++ b/Complexity/Computability/Circuit/Fusion/Graph.lean @@ -66,7 +66,7 @@ def literals {n : ℕ} (x : (Fin n → Bool) × (Fin n → Bool)) : Fin ((n + n) Fin.addCases (Fin.addCases x.1 x.2) (Fin.addCases (fun i => !x.1 i) (fun i => !x.2 i)) /-- Every literal containing a pair contains its row or its column. -/ -theorem literals_sourceRefinement {n : ℕ} (x : (Fin n → Bool) × (Fin n → Bool)) +private theorem literals_sourceRefinement {n : ℕ} (x : (Fin n → Bool) × (Fin n → Bool)) (i : Fin ((n + n) + (n + n))) (hi : literals x i = true) : ∃ j, x ∈ sources j ∧ sources j ⊆ {y | literals y i = true} := by let r := Fin.castAdd (Fintype.card (Fin n → Bool)) (Fintype.equivFin _ x.1) diff --git a/Complexity/Computability/Circuit/Fusion/Graph/Inequality.lean b/Complexity/Computability/Circuit/Fusion/Graph/Inequality.lean index fa1dd9c2c..863fa1c5e 100644 --- a/Complexity/Computability/Circuit/Fusion/Graph/Inequality.lean +++ b/Complexity/Computability/Circuit/Fusion/Graph/Inequality.lean @@ -119,7 +119,7 @@ theorem inequality_signature_injective tauto /-- A canonical cover needs enough bit signatures to label all vertices. -/ -theorem card_le_two_pow_length_inequality +private theorem card_le_two_pow_length_inequality (c : PairCover (inequality V) sources (canonicalClass (inequality V))) : Fintype.card V ≤ 2 ^ c.pairs.length := by simpa using Fintype.card_le_of_injective _ (inequality_signature_injective c) diff --git a/Complexity/Computability/Circuit/Fusion/Quadratic.lean b/Complexity/Computability/Circuit/Fusion/Quadratic.lean index 5c42373af..8f8ab8116 100644 --- a/Complexity/Computability/Circuit/Fusion/Quadratic.lean +++ b/Complexity/Computability/Circuit/Fusion/Quadratic.lean @@ -138,7 +138,7 @@ theorem stages_stable : simpa only [a, Finset.mem_filter, Finset.mem_univ, true_and] using this /-- All finite propagation stages are contained in the generated pair values. -/ -theorem stages_le_pairValues (k : ℕ) : +private theorem stages_le_pairValues (k : ℕ) : stages target input pairs k ≤ pairValues target input pairs := by induction k with | zero => exact bot_le @@ -180,7 +180,7 @@ noncomputable def stageCircuit (k : ℕ) : ((roundCircuit target input pairs).iterate k).comp (initialCircuit target pairs) /-- Each propagation round charges one conjunction per listed pair. -/ -theorem cost_stageCircuit (k : ℕ) : +private theorem cost_stageCircuit (k : ℕ) : (stageCircuit target input pairs k).program.cost Monotone.andCost = k * pairs.length := by rw [stageCircuit, Circuit.cost_program_comp, Circuit.cost_program_iterate, roundCircuit, Circuit.cost_program_append, Circuit.cost_program_wiring, cost_updateCircuit, @@ -329,7 +329,7 @@ theorem PairCover.size_toCircuit_le (c : PairCover target input) : nlinarith /-- Every unrestricted pair cover yields a quadratic upper bound for native AND complexity. -/ -theorem PairCover.ecomplexityFrom_le_sq (c : PairCover target input) : +private theorem PairCover.ecomplexityFrom_le_sq (c : PairCover target input) : ecomplexityFrom (Monotone.setInterpretation U) Monotone.andCost (fun _ : Unit => fun _ : Fin 1 => target) (fun _ => input) ≤ (c.pairs.length : ℕ∞) ^ 2 := by diff --git a/Complexity/Computability/Circuit/Iteration.lean b/Complexity/Computability/Circuit/Iteration.lean index 65b3a2106..e9827d727 100644 --- a/Complexity/Computability/Circuit/Iteration.lean +++ b/Complexity/Computability/Circuit/Iteration.lean @@ -112,7 +112,7 @@ def stages (q : ℕ → Set ((Fin n → U) → U)) (t : ℕ) : Set ((Fin n → U @[simp] theorem stages_zero (q : ℕ → Set ((Fin n → U) → U)) : stages q 0 = q 0 := by simp [stages] -theorem stages_succ (q : ℕ → Set ((Fin n → U) → U)) (t : ℕ) : +private theorem stages_succ (q : ℕ → Set ((Fin n → U) → U)) (t : ℕ) : stages q (t + 1) = stages q t ∪ q (t + 1) := by simp [stages, Finset.range_add_one, Set.union_comm] diff --git a/Complexity/Computability/Circuit/Linearize.lean b/Complexity/Computability/Circuit/Linearize.lean index 7dada6342..d03e327a4 100644 --- a/Complexity/Computability/Circuit/Linearize.lean +++ b/Complexity/Computability/Circuit/Linearize.lean @@ -109,7 +109,7 @@ theorem polynomialInterpretation_apply (R : Type*) [CommRing R] [Algebra F R] (o /-- Evaluation of a program with polynomial operations commutes with algebra homomorphisms. -/ -theorem Program.map_trace_polynomialInterpretation {R S : Type*} [CommRing R] [Algebra F R] +private theorem Program.map_trace_polynomialInterpretation {R S : Type*} [CommRing R] [Algebra F R] [CommRing S] [Algebra F S] (φ : R →ₐ[F] S) (p : Program σ n s) (x : Fin n → R) (w : Wire n s) : φ (p.trace (polynomialInterpretation P R) x w) = @@ -131,7 +131,7 @@ noncomputable def taylorOp (P : MvPolynomial (Fin k) F) (z : Fin k → F) : ⟨k, fun a => eval z (pderiv a P), eval z P - ∑ a, eval z (pderiv a P) * z a⟩ /-- The value of the first-order Taylor expansion of `P` at `z`. -/ -theorem affineInterpretation_taylorOp (P : MvPolynomial (Fin k) F) (z y : Fin k → F) : +private theorem affineInterpretation_taylorOp (P : MvPolynomial (Fin k) F) (z y : Fin k → F) : affineInterpretation F (taylorOp P z) y = eval z P + ∑ a, eval z (pderiv a P) * (y a - z a) := by simp only [taylorOp, affineInterpretation_apply, mul_sub, Finset.sum_sub_distrib] @@ -149,7 +149,7 @@ noncomputable def Program.linearize : ∀ {s : ℕ}, Program σ n s → Program line.wires⟩ /-- Linearization preserves the arity of every gate. -/ -theorem Program.arity_lines_linearize (p : Program σ n s) (g : Fin s) : +private theorem Program.arity_lines_linearize (p : Program σ n s) (g : Fin s) : (affineSignature F).Arity ((p.linearize P).lines g).op = σ.Arity (p.lines g).op := by induction p with | empty => exact g.elim0 @@ -161,18 +161,18 @@ theorem Program.arity_lines_linearize (p : Program σ n s) (g : Fin s) : exact ih g /-- Linearization preserves the inner gates. -/ -theorem Program.innerGates_linearize (p : Program σ n s) : +private theorem Program.innerGates_linearize (p : Program σ n s) : (p.linearize P).innerGates = p.innerGates := Finset.filter_congr fun g _ => by rw [arity_lines_linearize] /-- Linearization preserves fan-in. -/ -theorem Program.fanInAtMost_linearize (p : Program σ n s) (r : ℕ) : +private theorem Program.fanInAtMost_linearize (p : Program σ n s) (r : ℕ) : (p.linearize P).FanInAtMost r ↔ p.FanInAtMost r := by simp only [Program.fanInAtMost_iff] exact forall_congr' fun g => iff_of_eq (congrArg (· ≤ r) (p.arity_lines_linearize P g)) /-- The real part of the value of a wire at the input `ε x` is its value at the zero input. -/ -theorem Program.fst_trace_dualNumber (p : Program σ n s) (x : Fin n → F) (w : Wire n s) : +private theorem Program.fst_trace_dualNumber (p : Program σ n s) (x : Fin n → F) (w : Wire n s) : (p.trace (polynomialInterpretation P F[ε]) (fun j => inr (x j)) w).fst = p.trace (polynomialInterpretation P F) 0 w := p.map_trace_polynomialInterpretation P (fstHom F F F) _ w @@ -200,7 +200,7 @@ theorem Program.trace_linearize (p : Program σ n s) (x : Fin n → F) (w : Wire /-- Over an infinite field, a circuit with polynomial operations that computes `x ↦ M x` takes the value `ε (M x)_i` at its output `i` on the input `ε x`. -/ -theorem Circuit.trace_outputs_dualNumber [IsDomain F] [Infinite F] {c : Circuit σ n m} +private theorem Circuit.trace_outputs_dualNumber [IsDomain F] [Infinite F] {c : Circuit σ n m} {M : Matrix (Fin m) (Fin n) F} (hc : c.Computes (polynomialInterpretation P F) fun x => M *ᵥ x) (x : Fin n → F) (i : Fin m) : diff --git a/Complexity/Computability/Circuit/Monotone/BipartiteMatching.lean b/Complexity/Computability/Circuit/Monotone/BipartiteMatching.lean index cbadd5778..352d2a397 100644 --- a/Complexity/Computability/Circuit/Monotone/BipartiteMatching.lean +++ b/Complexity/Computability/Circuit/Monotone/BipartiteMatching.lean @@ -260,7 +260,7 @@ def oneRun (p : KWProtocol (Fin (n * n))) (h : Vertex m e ≃ Fin n) (i₀ : Fin variable {p : KWProtocol (Fin (n * n))} {h : Vertex m e ≃ Fin n} {i₀ : Fin m} /-- A run outputs Bob's answer on the edge found by `p`, relabelled back. -/ -theorem run_oneRun (σ : Relabeling m e) (x y : BitString m) : +private theorem run_oneRun (σ : Relabeling m e) (x y : BitString m) : (oneRun p h i₀ σ).run x y = bobAnswer i₀ y (relabel h σ (p.run (fun k => aliceGraph x (relabel h σ k)) fun k => bobGraph i₀ y (relabel h σ k))) := by simp only [oneRun, Protocol.run_bind, Protocol.run_comap, Protocol.run_bob, @@ -282,14 +282,14 @@ private theorem graph_relabel (h : Vertex m e ≃ Fin n) (σ : Relabeling m e) /-- The relabelled graphs are an instance of the monotone Karchmer–Wigderson game of bipartite perfect matching: Alice's has a perfect matching and Bob's has none. -/ -theorem bipartitePerfectMatching_aliceGraph (h : Vertex m e ≃ Fin n) (σ : Relabeling m e) +private theorem bipartitePerfectMatching_aliceGraph (h : Vertex m e ≃ Fin n) (σ : Relabeling m e) (x : BitString m) : bipartitePerfectMatching n (fun k => aliceGraph x (relabel h σ k)) = true := by rw [bipartitePerfectMatching_eq_true_iff, graph_relabel] exact (hasPerfectMatching_comp_iff _ _ _).mpr (hasPerfectMatching_aliceGraph x) /-- Bob's relabelled graph has no perfect matching. -/ -theorem bipartitePerfectMatching_bobGraph (h : Vertex m e ≃ Fin n) (σ : Relabeling m e) +private theorem bipartitePerfectMatching_bobGraph (h : Vertex m e ≃ Fin n) (σ : Relabeling m e) (y : BitString m) : bipartitePerfectMatching n (fun k => bobGraph i₀ y (relabel h σ k)) = false := by rw [Bool.eq_false_iff] diff --git a/Complexity/Computability/Circuit/Monotone/Clique/Essential.lean b/Complexity/Computability/Circuit/Monotone/Clique/Essential.lean index 0b8deac00..09fcfa496 100644 --- a/Complexity/Computability/Circuit/Monotone/Clique/Essential.lean +++ b/Complexity/Computability/Circuit/Monotone/Clique/Essential.lean @@ -43,7 +43,7 @@ open Cslib.Circuits.Clique Finset variable {n k : ℕ} /-- Monotone programs have fan-in at most two. -/ -theorem program_fanInAtMost_two {g : ℕ} (p : Program signature n g) : p.FanInAtMost 2 := by +private theorem program_fanInAtMost_two {g : ℕ} (p : Program signature n g) : p.FanInAtMost 2 := by induction p with | empty => trivial | gate p line ih => exact ⟨ih, by cases line.op <;> simp⟩ diff --git a/Complexity/Computability/Circuit/Monotone/Clique/LowerBound.lean b/Complexity/Computability/Circuit/Monotone/Clique/LowerBound.lean index dca575416..c2f71938d 100644 --- a/Complexity/Computability/Circuit/Monotone/Clique/LowerBound.lean +++ b/Complexity/Computability/Circuit/Monotone/Clique/LowerBound.lean @@ -46,11 +46,11 @@ variable {n k p w : ℕ} def negativeGateCap (n r p w : ℕ) : ℕ := (2 * sunflowerBound p w + sunflowerBound p w ^ 2) * Negative.pluckErrorCap n r p w -theorem Positive.errorCost_le (op : Op) : +private theorem Positive.errorCost_le (op : Op) : Positive.errorCost n k p w op ≤ Positive.errorCap n k p w := by cases op <;> simp [Positive.errorCost] -theorem Negative.errorCost_le (hp : 2 ≤ p) (r : ℕ) (op : Op) : +private theorem Negative.errorCost_le (hp : 2 ≤ p) (r : ℕ) (op : Op) : Negative.errorCost n r p w op ≤ negativeGateCap n r p w := by have hB := sunflowerBound_pos hp w unfold negativeGateCap @@ -90,7 +90,7 @@ theorem nonempty_outputApproximator (hw : 2 ≤ w) (hk : w + 1 ≤ k) /-- The approximator of the output of a circuit computing `k`-clique accepts only colourings with `k - 1` colours on which it is wrong, and so at most as many as the negative cost of the circuit. -/ -theorem card_acceptedColorings_le (hw : 2 ≤ w) (hk : 0 < k) +private theorem card_acceptedColorings_le (hw : 2 ≤ w) (hk : 0 < k) {C : Circuit signature (edgeCount n) 1} (hC : C.Computes interpretation (single (clique n k))) : (Negative.acceptedColorings (k - 1) (outputApproximator C : Approximator n p w).terms).card ≤ C.program.cost (Negative.errorCost n (k - 1) p w) := by diff --git a/Complexity/Computability/Circuit/Monotone/Clique/Negative.lean b/Complexity/Computability/Circuit/Monotone/Clique/Negative.lean index c5142064c..8dbf1f2e4 100644 --- a/Complexity/Computability/Circuit/Monotone/Clique/Negative.lean +++ b/Complexity/Computability/Circuit/Monotone/Clique/Negative.lean @@ -64,7 +64,7 @@ def collisionPairs (K s : Finset (Fin n)) : Finset (Fin n × Fin n) := uv ∈ collisionPairs K s ↔ uv.1 ∈ s ∧ uv.1 ∉ K ∧ uv.2 ∈ s ∧ uv.1 ≠ uv.2 := by simp [collisionPairs, and_assoc] -theorem card_collisionPairs_le {K s : Finset (Fin n)} (hs : s.card ≤ w) : +private theorem card_collisionPairs_le {K s : Finset (Fin n)} (hs : s.card ≤ w) : (collisionPairs K s).card ≤ w ^ 2 := calc (collisionPairs K s).card ≤ ((s \ K) ×ˢ s).card := card_le_card (filter_subset _ _) _ = (s \ K).card * s.card := card_product _ _ @@ -75,7 +75,7 @@ theorem card_collisionPairs_le {K s : Finset (Fin n)} (hs : s.card ≤ w) : abbrev Profile (S : Finset (Finset (Fin n))) (K : Finset (Fin n)) : Type := ∀ s : S, collisionPairs K s.1 -theorem card_profile_le {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} +private theorem card_profile_le {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (hS : ∀ s ∈ S, s.card ≤ w) : Fintype.card (Profile S K) ≤ (w ^ 2) ^ S.card := by rw [Fintype.card_pi] calc ∏ s : S, Fintype.card (collisionPairs K s.1) ≤ ∏ _s : S, w ^ 2 := @@ -83,7 +83,7 @@ theorem card_profile_le {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} _ = (w ^ 2) ^ S.card := by simp /-- The first vertices of the pairs of a profile. -/ -def selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (π : Profile S K) : +private def selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (π : Profile S K) : Finset (Fin n) := univ.image fun s => (π s).1.1 @@ -99,12 +99,13 @@ theorem fst_injective {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (hS : I rw [hS s.2 t.2 fun e => hne (Subtype.ext e)] at this exact hs.2.1 this -theorem card_selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (hS : IsSunflower S K) +private theorem card_selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} + (hS : IsSunflower S K) (π : Profile S K) : (selected π).card = S.card := by rw [selected, card_image_of_injective _ (fst_injective hS π), card_univ, Fintype.card_coe] /-- The second vertex of a collision pair is not selected. -/ -theorem snd_notMem_selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} +private theorem snd_notMem_selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (hS : IsSunflower S K) (π : Profile S K) (s : S) : (π s).1.2 ∉ selected π := by intro h obtain ⟨t, -, hts⟩ := mem_image.1 h @@ -118,12 +119,12 @@ theorem snd_notMem_selected {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} exact ht.2.1 this /-- The colourings giving both vertices of every pair of a profile the same colour. -/ -def profileColorings (r : ℕ) {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} +private def profileColorings (r : ℕ) {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (π : Profile S K) : Finset (Coloring n r) := univ.filter fun c => ∀ s, c (π s).1.1 = c (π s).1.2 /-- The colourings of a profile are determined by their colours outside the selected vertices. -/ -theorem card_profileColorings_le {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} +private theorem card_profileColorings_le {S : Finset (Finset (Fin n))} {K : Finset (Fin n)} (hS : IsSunflower S K) (π : Profile S K) : (profileColorings r π).card ≤ r ^ (n - S.card) := by let O := univ \ selected π @@ -143,7 +144,7 @@ theorem card_profileColorings_le {S : Finset (Finset (Fin n))} {K : Finset (Fin card_univ_sdiff, Fintype.card_fin, card_selected hS π] at this /-- A colouring injective on `K` but not on `s` has a collision pair in `s`. -/ -theorem exists_collisionPair {c : Coloring n r} {K s : Finset (Fin n)} +private theorem exists_collisionPair {c : Coloring n r} {K s : Finset (Fin n)} (hK : Set.InjOn c K) (hs : ¬Set.InjOn c s) : ∃ uv : collisionPairs K s, c uv.1.1 = c uv.1.2 := by simp only [Set.InjOn, not_forall] at hs @@ -192,7 +193,7 @@ noncomputable def stepExceptions (r : ℕ) (F G : Finset (Finset (Fin n))) : Fin simp [stepExceptions] /-- One pluck makes at most `pluckErrorCap n r p w` negative errors. -/ -theorem card_stepExceptions_le_of_pluck {F G : Finset (Finset (Fin n))} (h : Pluck p F G) +private theorem card_stepExceptions_le_of_pluck {F G : Finset (Finset (Fin n))} (h : Pluck p F G) (hF : ∀ s ∈ F, s.card ≤ w) : (stepExceptions r F G).card ≤ pluckErrorCap n r p w := by obtain ⟨S, hSF, hSp, K, hSK, rfl⟩ := h refine (card_le_card fun c hc => ?_).trans @@ -212,7 +213,8 @@ theorem stepExceptions_subset (r : ℕ) (F G H : Finset (Finset (Fin n))) : · exact mem_union_right _ (mem_stepExceptions.2 ⟨hH, hG⟩) /-- `m` plucks make at most `m` times `pluckErrorCap n r p w` negative errors. -/ -theorem card_stepExceptions_le_of_relatesInSteps (hp : 2 ≤ p) {F G : Finset (Finset (Fin n))} +private theorem card_stepExceptions_le_of_relatesInSteps (hp : 2 ≤ p) + {F G : Finset (Finset (Fin n))} {m : ℕ} (h : RelatesInSteps (Pluck p) F G m) (hF : ∀ s ∈ F, s.card ≤ w) : (stepExceptions r F G).card ≤ m * pluckErrorCap n r p w := by induction h with @@ -318,7 +320,7 @@ noncomputable def acceptedColorings (r : ℕ) (F : Finset (Finset (Fin n))) : Fi /-- At most `w ^ 2 * r ^ (n - 1)` colourings are not injective on a set of at most `w` vertices. -/ -theorem card_filter_not_injOn_le {s : Finset (Fin n)} (hs : s.card ≤ w) : +private theorem card_filter_not_injOn_le {s : Finset (Fin n)} (hs : s.card ≤ w) : (univ.filter fun c : Coloring n r => ¬Set.InjOn c s).card ≤ w ^ 2 * r ^ (n - 1) := by have hS : IsSunflower ({s} : Finset (Finset (Fin n))) ∅ := fun t ht u hu htu => by rw [coe_singleton, Set.mem_singleton_iff] at ht hu diff --git a/Complexity/Computability/Circuit/Monotone/Clique/Positive.lean b/Complexity/Computability/Circuit/Monotone/Clique/Positive.lean index 8c29a2d4c..db3b10b75 100644 --- a/Complexity/Computability/Circuit/Monotone/Clique/Positive.lean +++ b/Complexity/Computability/Circuit/Monotone/Clique/Positive.lean @@ -62,7 +62,7 @@ theorem card_superCliques {s : Finset (Fin n)} (hs : s.card ≤ k) : /-- A set of more than `w` vertices lies inside at most `C(n - w - 1, k - w - 1)` of the `k`-sets. -/ -theorem card_superCliques_le (hk : w + 1 ≤ k) {s : Finset (Fin n)} (hs : w < s.card) : +private theorem card_superCliques_le (hk : w + 1 ≤ k) {s : Finset (Fin n)} (hs : w < s.card) : (superCliques n k s).card ≤ (n - (w + 1)).choose (k - (w + 1)) := by obtain ⟨t, hts, ht⟩ := exists_subset_card_eq (s := s) (n := w + 1) (by omega) calc (superCliques n k s).card ≤ (superCliques n k t).card := @@ -75,7 +75,7 @@ def andExceptions (n k w : ℕ) (F G : Finset (Finset (Fin n))) : Finset (Clique ((F ×ˢ G).filter fun st => w < (join st.1 st.2).card).biUnion fun st => superCliques n k (join st.1 st.2) -theorem card_andExceptions_le (hk : w + 1 ≤ k) (F G : Finset (Finset (Fin n))) : +private theorem card_andExceptions_le (hk : w + 1 ≤ k) (F G : Finset (Finset (Fin n))) : (andExceptions n k w F G).card ≤ F.card * G.card * (n - (w + 1)).choose (k - (w + 1)) := by calc (andExceptions n k w F G).card ≤ ∑ st ∈ (F ×ˢ G).filter fun st => w < (join st.1 st.2).card, diff --git a/Complexity/Computability/Circuit/Monotone/DualRail.lean b/Complexity/Computability/Circuit/Monotone/DualRail.lean index 6a54874c5..192f963cd 100644 --- a/Complexity/Computability/Circuit/Monotone/DualRail.lean +++ b/Complexity/Computability/Circuit/Monotone/DualRail.lean @@ -72,7 +72,7 @@ def railBits (x : List Bool) : List Bool := true :: x.flatMap fun b => [b, !b] simp only [List.length_append, List.length_cons, List.length_nil] omega -theorem railBits_append (x : List Bool) (v : Bool) : +private theorem railBits_append (x : List Bool) (v : Bool) : railBits (x ++ [v]) = railBits x ++ [v, !v] := by simp [railBits] @@ -135,7 +135,7 @@ def dualCode (gates : List (Boolean.Op × List ℕ)) : List (Op × List ℕ) := | cons g gates ih => simp only [dualCode, List.flatMap_cons, List.length_append, length_dualGates, List.length_cons] at ih ⊢; omega -theorem dualCode_append (gates gates' : List (Boolean.Op × List ℕ)) : +private theorem dualCode_append (gates gates' : List (Boolean.Op × List ℕ)) : dualCode (gates ++ gates') = dualCode gates ++ dualCode gates' := List.flatMap_append @@ -324,7 +324,7 @@ theorem code_dualRail (c : Circuit Boolean.signature n m) : theorem size_dualRail (c : Circuit Boolean.signature n m) : (dualRail c).size = 2 * c.size := by rw [← Circuit.length_code_fst, code_dualRail, length_dualCode, Circuit.length_code_fst] -theorem toNat_outputs_dualRail (c : Circuit Boolean.signature n m) (j : Fin m) : +private theorem toNat_outputs_dualRail (c : Circuit Boolean.signature n m) (j : Fin m) : ((dualRail c).outputs j).toNat = railWire true (c.outputs j).toNat := by have h := congrArg Prod.snd (code_dualRail c) simp only [Circuit.code] at h diff --git a/Complexity/Computability/Circuit/Monotone/KarchmerWigderson.lean b/Complexity/Computability/Circuit/Monotone/KarchmerWigderson.lean index 1b76fe29f..63eec8549 100644 --- a/Complexity/Computability/Circuit/Monotone/KarchmerWigderson.lean +++ b/Complexity/Computability/Circuit/Monotone/KarchmerWigderson.lean @@ -85,7 +85,8 @@ def monotoneKWProtocol : Formula Monotone.signature n → KWProtocol (Fin n) /-- The protocol of a monotone formula finds a bit that is one in Alice's input and zero in Bob's, when the formula is true on Alice's input and false on Bob's. -/ -theorem exceedsAt_run_monotoneKWProtocol (F : Formula Monotone.signature n) {x y : BitString n} +private theorem exceedsAt_run_monotoneKWProtocol (F : Formula Monotone.signature n) + {x y : BitString n} (hx : F.eval interpretation x = true) (hy : F.eval interpretation y = false) : ExceedsAt x y (F.monotoneKWProtocol.run x y) := by induction F with diff --git a/Complexity/Computability/Circuit/Rational/Affine.lean b/Complexity/Computability/Circuit/Rational/Affine.lean index b63fae0d9..452eb8388 100644 --- a/Complexity/Computability/Circuit/Rational/Affine.lean +++ b/Complexity/Computability/Circuit/Rational/Affine.lean @@ -192,53 +192,53 @@ section Native variable (q : ℚ) (i : Fin n) (a : Fin (ratSignature.Arity .add) → Formula n) (m : Fin (ratSignature.Arity .mul) → Formula n) (b : Fin (ratSignature.Arity .inv) → Formula n) -theorem realized_add : realized c X (.gate .add a) = +private theorem realized_add : realized c X (.gate .add a) = fromBlocks (realized c X (a 0)) 0 0 (realized c X (a 1)) := by change (fromBlocks (pencil (a 0)) 0 0 (pencil (a 1))).map (Affine.eval c X) = _ rw [fromBlocks_map] simp -theorem realized_mul : realized c X (.gate .mul m) = +private theorem realized_mul : realized c X (.gate .mul m) = fromBlocks (realized c X (m 0)) (-colR c (m 0) * rowR c (m 1)) 0 (realized c X (m 1)) := by change (fromBlocks (pencil (m 0)) (-Affine.constMatrix (col (m 0) * row (m 1))) 0 (pencil (m 1))).map (Affine.eval c X) = _ rw [fromBlocks_map, Matrix.map_neg _ (map_neg _)] simp [Matrix.map_mul, Matrix.neg_mul, rowR, colR] -theorem realized_inv : realized c X (.gate .inv b) = +private theorem realized_inv : realized c X (.gate .inv b) = fromBlocks (realized c X (b 0)) (colR c (b 0)) (rowR c (b 0)) 0 := by change (fromBlocks (pencil (b 0)) (Affine.constMatrix (col (b 0))) (Affine.constMatrix (row (b 0))) 0).map (Affine.eval c X) = _ rw [fromBlocks_map] simp [rowR, colR] -theorem rowR_add : rowR c (.gate .add a) = fromCols (rowR c (a 0)) (rowR c (a 1)) := +private theorem rowR_add : rowR c (.gate .add a) = fromCols (rowR c (a 0)) (rowR c (a 1)) := fromCols_map _ _ _ -theorem colR_add : colR c (.gate .add a) = fromRows (colR c (a 0)) (colR c (a 1)) := +private theorem colR_add : colR c (.gate .add a) = fromRows (colR c (a 0)) (colR c (a 1)) := fromRows_map _ _ _ -theorem rowR_mul : rowR c (.gate .mul m) = fromCols (rowR c (m 0)) 0 := by +private theorem rowR_mul : rowR c (.gate .mul m) = fromCols (rowR c (m 0)) 0 := by change (fromCols (row (m 0)) 0).map c = _ rw [fromCols_map] simp -theorem colR_mul : colR c (.gate .mul m) = fromRows 0 (colR c (m 1)) := by +private theorem colR_mul : colR c (.gate .mul m) = fromRows 0 (colR c (m 1)) := by change (fromRows 0 (col (m 1))).map c = _ rw [fromRows_map] simp -theorem rowR_inv : rowR c (.gate .inv b) = fromCols 0 (-1) := by +private theorem rowR_inv : rowR c (.gate .inv b) = fromCols 0 (-1) := by change (fromCols (0 : Matrix Unit (Index (b 0)) ℚ) (-1)).map c = _ rw [fromCols_map, Matrix.map_neg _ (map_neg _)] simp -theorem colR_inv : colR c (.gate .inv b) = fromRows 0 1 := by +private theorem colR_inv : colR c (.gate .inv b) = fromRows 0 1 := by change (fromRows (0 : Matrix (Index (b 0)) Unit ℚ) 1).map c = _ rw [fromRows_map] simp -theorem realized_input : realized c X (.input i) = fromBlocks 1 (-scalar (X i)) 0 1 := by +private theorem realized_input : realized c X (.input i) = fromBlocks 1 (-scalar (X i)) 0 1 := by change (fromBlocks (Affine.constMatrix (1 : Matrix Unit Unit ℚ)) (Matrix.of fun _ _ => -Affine.varForm i) 0 (Affine.constMatrix 1)).map (Affine.eval c X) = _ rw [fromBlocks_map] @@ -248,7 +248,7 @@ theorem realized_input : realized c X (.input i) = fromBlocks 1 (-scalar (X i)) ext simp [scalar, Matrix.map, Matrix.of_apply] -theorem realized_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : +private theorem realized_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : realized c X (.gate (.const q) args) = fromBlocks 1 (-scalar (c q)) 0 1 := by change (fromBlocks (Affine.constMatrix (1 : Matrix Unit Unit ℚ)) (Matrix.of fun _ _ => -Affine.constant q) 0 (Affine.constMatrix 1)).map @@ -260,23 +260,23 @@ theorem realized_const (args : Fin (ratSignature.Arity (.const q)) → Formula n ext simp [scalar, Matrix.map, Matrix.of_apply] -theorem rowR_input : rowR c (.input i) = fromCols 1 0 := by +private theorem rowR_input : rowR c (.input i) = fromCols 1 0 := by change (fromCols (1 : Matrix Unit Unit ℚ) 0).map c = _ rw [fromCols_map] simp -theorem colR_input : colR c (.input i) = fromRows 0 1 := by +private theorem colR_input : colR c (.input i) = fromRows 0 1 := by change (fromRows 0 (1 : Matrix Unit Unit ℚ)).map c = _ rw [fromRows_map] simp -theorem rowR_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : +private theorem rowR_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : rowR c (.gate (.const q) args) = fromCols 1 0 := by change (fromCols (1 : Matrix Unit Unit ℚ) 0).map c = _ rw [fromCols_map] simp -theorem colR_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : +private theorem colR_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : colR c (.gate (.const q) args) = fromRows 0 1 := by change (fromRows 0 (1 : Matrix Unit Unit ℚ)).map c = _ rw [fromRows_map] @@ -284,7 +284,7 @@ theorem colR_const (args : Fin (ratSignature.Arity (.const q)) → Formula n) : end Native -theorem leaf_realization (a : R) : +private theorem leaf_realization (a : R) : ∃ M : Matrix (Unit ⊕ Unit) (Unit ⊕ Unit) R, fromBlocks 1 (-scalar a) 0 1 * M = 1 ∧ M * fromBlocks 1 (-scalar a) 0 1 = 1 ∧ @@ -390,7 +390,7 @@ def inverseNodes : Formula n → List (Formula n) not a new counted gate. -/ def certificates (f : Formula n) : List (Formula n) := inverseNodes f ++ [inv f] -theorem Eval.pencil_isUnit {f : Formula n} {a : R} (ha : f.Eval c X a) : +private theorem Eval.pencil_isUnit {f : Formula n} {a : R} (ha : f.Eval c X a) : IsUnit (realized c X f) := by obtain ⟨M, hM, hM', _⟩ := ha.realization exact isUnit_iff_exists.mpr ⟨M, hM, hM'⟩ @@ -405,7 +405,7 @@ theorem Eval.augmented_isUnit_iff {f : Formula n} {a : R} (ha : f.Eval c X a) : refine key.trans ⟨fun h => ?_, fun h => h.map (Matrix.uniqueRingEquiv (m := Unit)).symm⟩ simpa using h.map (Matrix.uniqueRingEquiv (m := Unit)) -theorem Eval.inverseNodes_units {f : Formula n} {a : R} (ha : f.Eval c X a) : +private theorem Eval.inverseNodes_units {f : Formula n} {a : R} (ha : f.Eval c X a) : ∀ h ∈ inverseNodes f, IsUnit (realized c X h) := by induction f using inductionOn generalizing a with | var i => simp @@ -460,7 +460,7 @@ theorem certificates_iff (f : Formula n) : · obtain rfl : h = inv f := by simpa using hh exact ha.augmented_isUnit_iff.mpr hua -theorem inverseNodes_length (f : Formula n) : (inverseNodes f).length ≤ f.nodeCount := by +private theorem inverseNodes_length (f : Formula n) : (inverseNodes f).length ≤ f.nodeCount := by induction f using inductionOn with | var i => simp | const q => simp @@ -530,7 +530,7 @@ theorem homogeneous_one (c : ℚ →+* R) (X : Fin n → R) (a : Form n) : homogeneous c (Fin.cases 1 X) a = eval c X a := by simp [homogeneous, coeff, Fin.sum_univ_succ, eval] -theorem normalized [Algebra ℚ R] (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u = 1) +private theorem normalized [Algebra ℚ R] (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u = 1) (a : Form n) : homogeneous (algebraMap ℚ R) Z a = Z 0 * eval (algebraMap ℚ R) (fun i => u * Z i.succ) a := by @@ -545,7 +545,7 @@ theorem normalized [Algebra ℚ R] (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u rw [← mul_assoc, ← Algebra.commutes (a.2 i) (Z 0), mul_assoc, ← mul_assoc (Z 0) u, hu, one_mul] -theorem normalized_pencil {ι : Type*} [Fintype ι] [DecidableEq ι] [Algebra ℚ R] +private theorem normalized_pencil {ι : Type*} [Fintype ι] [DecidableEq ι] [Algebra ℚ R] (L : Matrix ι ι (Form n)) (Z : Fin (n + 1) → R) (u : R) (hu : Z 0 * u = 1) : L.map (homogeneous (algebraMap ℚ R) Z) = Matrix.scalar ι (Z 0) * L.map (eval (algebraMap ℚ R) (fun i => u * Z i.succ)) := by diff --git a/Complexity/Computability/Circuit/Rational/BlockDivision.lean b/Complexity/Computability/Circuit/Rational/BlockDivision.lean index 98ef2bbc1..9f3a3d4e3 100644 --- a/Complexity/Computability/Circuit/Rational/BlockDivision.lean +++ b/Complexity/Computability/Circuit/Rational/BlockDivision.lean @@ -92,7 +92,7 @@ lemma embed_monomial (m : Fin 2 →₀ ℕ) (a : K) : simp [variableSeries, Fin.prod_univ_two, HahnSeries.single_pow, HahnSeries.single_mul_single, HahnSeries.algebraMap_apply, HahnSeries.C_apply, he] -lemma embed_coeff (p : MvPolynomial (Fin 2) K) (m : Fin 2 →₀ ℕ) : +private lemma embed_coeff (p : MvPolynomial (Fin 2) K) (m : Fin 2 →₀ ℕ) : (embed p).coeff (exponent m) = p.coeff m := by classical conv_lhs => rw [p.as_sum] diff --git a/Complexity/Computability/Circuit/Rational/Certificates.lean b/Complexity/Computability/Circuit/Rational/Certificates.lean index ee91add0a..09b3a1cc1 100644 --- a/Complexity/Computability/Circuit/Rational/Certificates.lean +++ b/Complexity/Computability/Circuit/Rational/Certificates.lean @@ -78,7 +78,7 @@ def evaluate (ev : P →+* K) : Regular ev →+* K := /-- Only fractions whose denominator is nonzero at the point are evaluated. The entire division algebra is deliberately not given a specialization. -/ -lemma evaluate_reflects_units (ev : P →+* K) (x : Regular ev) +private lemma evaluate_reflects_units (ev : P →+* K) (x : Regular ev) (hx : IsUnit (evaluate ev x)) : IsUnit x := by obtain ⟨a, b, rfl⟩ := IsLocalization.exists_mk'_eq (denominators ev) x have heq : ev a = ev b * evaluate ev (IsLocalization.mk' (Regular ev) a b) := @@ -111,7 +111,7 @@ lemma intoField_injective (ev : P →+* K) (j : P →+* E) (hj : Function.Inject rw [hj h] variable {ι : Type*} [Fintype ι] [DecidableEq ι] -lemma matrix_reflects_units (ev : P →+* K) (A : Matrix ι ι (Regular ev)) +private lemma matrix_reflects_units (ev : P →+* K) (A : Matrix ι ι (Regular ev)) (hA : IsUnit ((evaluate ev).mapMatrix A)) : IsUnit A := by rw [Matrix.isUnit_iff_isUnit_det] at hA ⊢ apply evaluate_reflects_units ev @@ -277,7 +277,7 @@ lemma specialized (χ : AddChar (ZMod M) K) simp only [RingHom.mapMatrix_apply, Matrix.map_apply, polynomial_apply, map_sum, map_mul, eval₂Hom_C, RingHom.id_apply] -lemma block_eq (φ : K →+* E) (L : Matrix (Fin q) (Fin q) (Affine.Form n)) +private lemma block_eq (φ : K →+* E) (L : Matrix (Fin q) (Fin q) (Affine.Form n)) {d : ℕ} (X : Fin n → Matrix (Fin d) (Fin d) E) : Rectangular.blockMatrix (fun i => φ.mapMatrix (coefficients (K := K) L i)) (Fin.cases 1 X) = Matrix.compRingEquiv (Fin q) (Fin d) E (L.map (Affine.eval (algebraMap ℚ _) X)) := by diff --git a/Complexity/Computability/Circuit/Rational/CyclotomicGrid.lean b/Complexity/Computability/Circuit/Rational/CyclotomicGrid.lean index bdba81193..f953194a5 100644 --- a/Complexity/Computability/Circuit/Rational/CyclotomicGrid.lean +++ b/Complexity/Computability/Circuit/Rational/CyclotomicGrid.lean @@ -68,7 +68,7 @@ noncomputable section /-- The cyclotomic modulus for roots of unity of power-of-two order. -/ def modulus (e : ℕ) : ℚ[X] := X ^ (2 ^ e) + 1 -lemma modulus_eq_cyclotomic (e : ℕ) : modulus e = cyclotomic (dimension e) ℚ := by +private lemma modulus_eq_cyclotomic (e : ℕ) : modulus e = cyclotomic (dimension e) ℚ := by rw [dimension, cyclotomic_prime_pow_eq_geom_sum Nat.prime_two] simp [modulus, Finset.sum_range_succ, add_comm] diff --git a/Complexity/Computability/Circuit/Rational/Deformation.lean b/Complexity/Computability/Circuit/Rational/Deformation.lean index 3511ed12d..ec623ef0b 100644 --- a/Complexity/Computability/Circuit/Rational/Deformation.lean +++ b/Complexity/Computability/Circuit/Rational/Deformation.lean @@ -105,13 +105,13 @@ def blockOriginal (A : Matrix m m (Matrix (ZMod d) (ZMod d) K)) : Matrix (m × ZMod d) (m × ZMod d) K := fun i j => A i.1 j.1 i.2 j.2 omit [CharZero K] in -lemma blockPolynomial_embed (A : Matrix m m (Matrix (ZMod d) (ZMod d) K)) : +private lemma blockPolynomial_embed (A : Matrix m m (Matrix (ZMod d) (ZMod d) K)) : PolynomialHahn.embed.mapMatrix (blockPolynomial χ A) = blockEmbedding (representation χ) (fun i j => liftD χ (A i j)) := by funext ⟨i, a⟩ ⟨j, b⟩ exact congrFun (congrFun (polynomialLift_embed χ (A i j)) a) b -lemma blockPolynomial_specialize (hχ : χ.IsPrimitive) +private lemma blockPolynomial_specialize (hχ : χ.IsPrimitive) (A : Matrix m m (Matrix (ZMod d) (ZMod d) K)) : (MvPolynomial.aeval (fun _ : Fin 2 => (1 : K))).toRingHom.mapMatrix (blockPolynomial χ A) = blockOriginal A := by @@ -171,7 +171,7 @@ def specialize (φ : K →+* E) (t : E) : MvPolynomial (Fin 3) K →+* MvPolynomial (Fin 2) E := eval₂Hom (MvPolynomial.C.comp φ) (Fin.cases (MvPolynomial.C t) MvPolynomial.X) -lemma specialize_uni (φ : K →+* E) (t : E) (p : K[X]) : +private lemma specialize_uni (φ : K →+* E) (t : E) (p : K[X]) : specialize φ t (uni p) = MvPolynomial.C (p.eval₂ φ t) := by have he : (specialize φ t).comp uni = MvPolynomial.C.comp (Polynomial.eval₂RingHom φ t) := by @@ -189,11 +189,11 @@ lemma coeffP_eval (φ : K →+* E) (t : E) simp [coeffP, QuantumMatrices.fourierCoeff, Polynomial.eval₂_mul, Polynomial.eval₂_finsetSum] omit [NeZero d] in -lemma weyl_map (φ : K →+* E) (a b i j : ZMod d) : +private lemma weyl_map (φ : K →+* E) (a b i j : ZMod d) : φ (weyl χ a b i j) = weyl (φ.toMonoidHom.compAddChar χ) a b i j := by by_cases h : i = j + b <;> simp [weyl, h] -lemma specialize_lift (φ : K →+* E) (t : E) +private lemma specialize_lift (φ : K →+* E) (t : E) (R : Matrix (ZMod d) (ZMod d) K[X]) : (specialize φ t).mapMatrix (lift χ R) = polynomialLift (φ.toMonoidHom.compAddChar χ) ((Polynomial.eval₂RingHom φ t).mapMatrix R) := by @@ -209,7 +209,7 @@ lemma specialize_lift (φ : K →+* E) (t : E) rw [MvPolynomial.monomial_add_single, ← MvPolynomial.C_mul_X_pow_eq_monomial, map_mul] rfl -lemma uni_totalDegree_le (p : K[X]) : (uni p).totalDegree ≤ p.natDegree := by +private lemma uni_totalDegree_le (p : K[X]) : (uni p).totalDegree ≤ p.natDegree := by classical conv_lhs => rw [p.as_sum_range_C_mul_X_pow] simp only [map_sum, map_mul, map_pow] @@ -221,7 +221,7 @@ lemma uni_totalDegree_le (p : K[X]) : (uni p).totalDegree ≤ p.natDegree := by simp only [zero_add, totalDegree_X, Nat.mul_one] exact Nat.le_of_lt_succ (Finset.mem_range.mp hj) -lemma coeffP_natDegree_le (R : Matrix (ZMod d) (ZMod d) K[X]) (D : ℕ) +private lemma coeffP_natDegree_le (R : Matrix (ZMod d) (ZMod d) K[X]) (D : ℕ) (hR : ∀ i j, (R i j).natDegree ≤ D) (a b : ZMod d) : (coeffP χ R a b).natDegree ≤ D := by apply (Polynomial.natDegree_C_mul_le _ _).trans @@ -229,7 +229,7 @@ lemma coeffP_natDegree_le (R : Matrix (ZMod d) (ZMod d) K[X]) (D : ℕ) intro j _ exact (Polynomial.natDegree_C_mul_le _ _).trans (hR _ _) -lemma lift_totalDegree_le (R : Matrix (ZMod d) (ZMod d) K[X]) (D : ℕ) +private lemma lift_totalDegree_le (R : Matrix (ZMod d) (ZMod d) K[X]) (D : ℕ) (hR : ∀ i j, (R i j).natDegree ≤ D) (i j : ZMod d) : (lift χ R i j).totalDegree ≤ D + 2 * (d - 1) := by apply totalDegree_finsetSum_le @@ -272,7 +272,7 @@ def polynomial (χ : AddChar (ZMod M) K) fun a b => ThreeLift.lift χ (polyBlocks (M := M) (N := N) A points a.1 b.1) a.2 b.2 omit [CharZero K] [CharZero E] in -lemma specialize (χ : AddChar (ZMod M) K) +private lemma specialize (χ : AddChar (ZMod M) K) (φ : K →+* E) (t : E) (A : Fin w → Matrix (Fin q) (Fin q) K) (points : Fin w → K) : (ThreeLift.specialize φ t).mapMatrix (polynomial (N := N) χ A points) = QuantumLift.blockPolynomial (φ.toMonoidHom.compAddChar χ) @@ -282,7 +282,7 @@ lemma specialize (χ : AddChar (ZMod M) K) exact congrFun (congrFun (ThreeLift.specialize_lift χ φ t (polyBlocks A points α β)) i) j omit [CharZero K] [CharZero E] in -lemma raw_specialize (φ : K →+* E) +private lemma raw_specialize (φ : K →+* E) (A : Fin w → Matrix (Fin q) (Fin q) K) (points : Fin w → K) : QuantumLift.blockOriginal (fun α β => (Polynomial.eval₂RingHom ((HahnSeries.C : E →+* F E).comp φ) @@ -338,7 +338,7 @@ theorem det_ne_zero (χ : AddChar (ZMod M) K) (hχ : χ.IsPrimitive) exact hd hm omit [CharZero K] in -lemma polyBlocks_degree (A : Fin w → Matrix (Fin q) (Fin q) K) (points : Fin w → K) +private lemma polyBlocks_degree (A : Fin w → Matrix (Fin q) (Fin q) K) (points : Fin w → K) (α β : Fin q) (i j : ZMod M) : (polyBlocks (M := M) (N := N) A points α β i j).natDegree ≤ M - 1 := by simp only [polyBlocks, Matrix.sum_apply, Matrix.smul_apply, Polynomial.smul_eq_C_mul] @@ -367,13 +367,13 @@ noncomputable section variable {K : Type*} [Field K] {d : ℕ} [NeZero d] variable (χ : AddChar (ZMod d) K) -lemma coeffP_zero (a b : ZMod d) : coeffP χ 0 a b = 0 := by simp [coeffP] +private lemma coeffP_zero (a b : ZMod d) : coeffP χ 0 a b = 0 := by simp [coeffP] -lemma coeffP_add (R S : Matrix (ZMod d) (ZMod d) K[X]) (a b : ZMod d) : +private lemma coeffP_add (R S : Matrix (ZMod d) (ZMod d) K[X]) (a b : ZMod d) : coeffP χ (R + S) a b = coeffP χ R a b + coeffP χ S a b := by simp [coeffP, mul_add, Finset.sum_add_distrib] -lemma coeffP_smul (c : K) (R : Matrix (ZMod d) (ZMod d) K[X]) (a b : ZMod d) : +private lemma coeffP_smul (c : K) (R : Matrix (ZMod d) (ZMod d) K[X]) (a b : ZMod d) : coeffP χ (c • R) a b = Polynomial.C c * coeffP χ R a b := by simp only [coeffP, Matrix.smul_apply, Polynomial.smul_eq_C_mul, Finset.mul_sum] apply Finset.sum_congr rfl diff --git a/Complexity/Computability/Circuit/Rational/Determinant.lean b/Complexity/Computability/Circuit/Rational/Determinant.lean index 0595effff..1bfd3eb2c 100644 --- a/Complexity/Computability/Circuit/Rational/Determinant.lean +++ b/Complexity/Computability/Circuit/Rational/Determinant.lean @@ -78,7 +78,7 @@ def stages {n : ℕ} (A : Table n) : ℕ → Table n | 0 => A | k + 1 => step A (stages A k) -lemma stages_spec {n : ℕ} (A : Table n) (k : ℕ) : +private lemma stages_spec {n : ℕ} (A : Table n) (k : ℕ) : denote (stages A k) = (BirdDet.Spec.stepEntry (denote A))^[k] (denote A) := by induction k with | zero => rfl diff --git a/Complexity/Computability/Circuit/Rational/EncodingBounds.lean b/Complexity/Computability/Circuit/Rational/EncodingBounds.lean index 802470baf..b989c2d64 100644 --- a/Complexity/Computability/Circuit/Rational/EncodingBounds.lean +++ b/Complexity/Computability/Circuit/Rational/EncodingBounds.lean @@ -56,25 +56,26 @@ namespace Rational.EncodingBounds open Matrix open scoped BigOperators -lemma encodeNat_length (a : ℕ) : (encodeNat a).length = 2 * (Nat.digits 2 a).length + 1 := by +private lemma encodeNat_length (a : ℕ) : + (encodeNat a).length = 2 * (Nat.digits 2 a).length + 1 := by simp only [encodeNat, List.length_append, List.length_replicate, List.length_map, List.length_cons, List.length_nil] omega -lemma encodeNat_le (a L : ℕ) (ha : a < 2 ^ L) : (encodeNat a).length ≤ 2 * L + 1 := by +private lemma encodeNat_le (a L : ℕ) (ha : a < 2 ^ L) : (encodeNat a).length ≤ 2 * L + 1 := by rw [encodeNat_length] exact Nat.add_le_add_right (Nat.mul_le_mul_left 2 ((Nat.digits_length_le_iff (by omega) a).mpr ha)) 1 -lemma ratio_num_le (a b : ℤ) (hb : b ≠ 0) : (Rat.divInt a b).num.natAbs ≤ a.natAbs := by +private lemma ratio_num_le (a b : ℤ) (hb : b ≠ 0) : (Rat.divInt a b).num.natAbs ≤ a.natAbs := by by_cases ha : a = 0 · simp [ha] · exact Int.natAbs_le_of_dvd_ne_zero (Rat.num_dvd a hb) ha -lemma ratio_den_le (a b : ℤ) (hb : b ≠ 0) : (Rat.divInt a b).den ≤ b.natAbs := by +private lemma ratio_den_le (a b : ℤ) (hb : b ≠ 0) : (Rat.divInt a b).den ≤ b.natAbs := by simpa only [Int.natAbs_natCast] using Int.natAbs_le_of_dvd_ne_zero (Rat.den_dvd a b) hb -lemma encodeRat_ratio_le (a b : ℤ) (hb : b ≠ 0) (L : ℕ) +private lemma encodeRat_ratio_le (a b : ℤ) (hb : b ≠ 0) (L : ℕ) (ha : a.natAbs < 2 ^ L) (hb' : b.natAbs < 2 ^ L) : (encodeRat (Rat.divInt a b)).length ≤ 4 * L + 3 := by have hn := encodeNat_le _ L (lt_of_le_of_lt (ratio_num_le a b hb) ha) @@ -82,7 +83,7 @@ lemma encodeRat_ratio_le (a b : ℤ) (hb : b ≠ 0) (L : ℕ) simp only [encodeRat, List.length_append, List.length_singleton] omega -lemma determinant_bound {d : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) (B : ℕ) +private lemma determinant_bound {d : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) (B : ℕ) (hA : ∀ i j, |A i j| ≤ B) : |A.det| ≤ (d.factorial : ℤ) * (B : ℤ) ^ d := by have h := Matrix.det_le (abv := AbsoluteValue.abs) (x := (B : ℤ)) (A := A) (by simpa using hA) simpa only [AbsoluteValue.abs_apply, nsmul_eq_mul, Fintype.card_fin] using h @@ -117,7 +118,7 @@ lemma normalized_entry_ratio {d : ℕ} (A B : Matrix (Fin d) (Fin d) ℤ) (hA : rw [he] at hi exact hi -lemma determinant_pow_bound {d b : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) +private lemma determinant_pow_bound {d b : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) (hA : ∀ i j, |A i j| ≤ (2 : ℤ) ^ b) : |A.det| < (2 : ℤ) ^ (d * d + d * b + 1) := by have hb := determinant_bound A (2 ^ b) (by simpa using hA) have hf : d.factorial ≤ (2 ^ d) ^ d := @@ -150,7 +151,7 @@ lemma normalization_bit_bound {d b : ℕ} (A B : Matrix (Fin d) (Fin d) ℤ) (hA rw [← Int.natCast_natAbs] at h exact_mod_cast h -lemma tuple_length_le {n d B : ℕ} (X : Tuple n d) +private lemma tuple_length_le {n d B : ℕ} (X : Tuple n d) (h : ∀ a i j, (encodeRat (X a i j)).length ≤ B) : (encodeTuple X).length ≤ n * d * d * B := by unfold encodeTuple @@ -166,7 +167,7 @@ lemma tuple_length_le {n d B : ℕ} (X : Tuple n d) _ = _ := by simp _ = _ := by simp [Nat.mul_assoc] -lemma encodeNat_linear (a : ℕ) : (encodeNat a).length ≤ 2 * (a + 1) + 1 := by +private lemma encodeNat_linear (a : ℕ) : (encodeNat a).length ≤ 2 * (a + 1) + 1 := by apply encodeNat_le have h : a ≤ 2 ^ a := Nat.lt_two_pow_self.le have hp : 0 < 2 ^ a := by positivity @@ -190,11 +191,12 @@ end Rational.EncodingBounds namespace Rational.PolynomialBounds /-- Coefficient/exponent bookkeeping, with no symbolic expansion of large powers. -/ -lemma mul_monomials (a b m i j : ℕ) : (a * m ^ i) * (b * m ^ j) = (a * b) * m ^ (i + j) := by +private lemma mul_monomials (a b m i j : ℕ) : + (a * m ^ i) * (b * m ^ j) = (a * b) * m ^ (i + j) := by rw [pow_add] ac_rfl -lemma lift_power (c m i j : ℕ) (hm : 1 ≤ m) (hij : i ≤ j) : c * m ^ i ≤ c * m ^ j := +private lemma lift_power (c m i j : ℕ) (hm : 1 ≤ m) (hij : i ≤ j) : c * m ^ i ≤ c * m ^ j := Nat.mul_le_mul_left c (Nat.pow_le_pow_right hm hij) /-- Exponent bounding all denominator-cleared matrix entries by a power of 2. -/ @@ -237,7 +239,7 @@ theorem logarithmic_bound (n s : ℕ) : /-- Fixed coefficient in the bound on normalized rational entry encodings. -/ def bitConstant : ℕ := 4 * (256 * 256 + 256 * logConstant + 1) + 3 -theorem normalized_bits_bound (m D b : ℕ) (hm : 1 ≤ m) +private theorem normalized_bits_bound (m D b : ℕ) (hm : 1 ≤ m) (hD : D ≤ 256 * m ^ 10) (hb : b ≤ logConstant * m ^ 22) : 4 * (D * D + D * b + 1) + 3 ≤ bitConstant * m ^ 32 := by have h₁ : D * D ≤ (256 * 256) * m ^ 32 := by @@ -258,7 +260,7 @@ source's constant: the bound also covers `n = 0`, which raises the grid-size coe def outputConstant : ℕ := (2 * 256 + 3) + (2 * 49153 ^ 3 + 3) + 49153 ^ 3 * 256 * 256 * bitConstant -theorem output_bits_bound (n m D L B : ℕ) (hm : 1 ≤ m) (hn : n ≤ m) +private theorem output_bits_bound (n m D L B : ℕ) (hm : 1 ≤ m) (hn : n ≤ m) (hD : D ≤ 256 * m ^ 10) (hL : L ≤ 49153 ^ 3 * m ^ 51) (hB : B ≤ bitConstant * m ^ 32) : 2 * (D + 1) + 1 + 2 * (L + 1) + 1 + L * n * D * D * B ≤ outputConstant * m ^ 104 := by have hp := Nat.one_le_pow 104 m hm @@ -278,7 +280,7 @@ namespace Rational.Generator open Matrix EncodingBounds open scoped BigOperators -lemma U_power_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ l, x l ≤ H) +private lemma U_power_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ l, x l ≤ H) (a : Fin (n + 1)) (i j : Fin (matrixDimension e)) : |integralLift n N e x a i j| ≤ (2 : ℤ) ^ (4 * CyclotomicRing.dimension e + 4 * CyclotomicRing.dimension e * (n + 1) + 3 * CyclotomicRing.dimension e * H) := by @@ -297,7 +299,7 @@ lemma U_power_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ dsimp [M] ring -lemma tupleAt_bit_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ l, x l ≤ H) +private lemma tupleAt_bit_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ l, x l ≤ H) (hz : (rationalLift n N e x 0).det ≠ 0) (a : Fin n) (i j : Fin (matrixDimension e)) : (encodeRat (tupleAt n N e x a i j)).length ≤ 4 * (matrixDimension e * matrixDimension e + matrixDimension e * @@ -307,7 +309,7 @@ lemma tupleAt_bit_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : exact normalization_bit_bound _ _ (U_det_ne_zero n N e x hz) (U_power_bound n N e H x hH hx 0) (U_power_bound n N e H x hH hx a.succ) i j -lemma output_entry_bit_bound (n N e H : ℕ) (hH : 1 ≤ H) +private lemma output_entry_bit_bound (n N e H : ℕ) (hH : 1 ≤ H) (X : Tuple n (matrixDimension e)) (hX : X ∈ (output n N e H).tuples) (a : Fin n) (i j : Fin (matrixDimension e)) : (encodeRat (X a i j)).length ≤ diff --git a/Complexity/Computability/Circuit/Rational/Eval.lean b/Complexity/Computability/Circuit/Rational/Eval.lean index c23ab3597..9ea8da563 100644 --- a/Complexity/Computability/Circuit/Rational/Eval.lean +++ b/Complexity/Computability/Circuit/Rational/Eval.lean @@ -152,14 +152,14 @@ abbrev matMul {l m n : Type*} [Fintype m] (A : Matrix l m R) (B : Matrix m n R) Matrix l n R := A * B /-- An upper unitriangular block matrix is invertible. -/ -theorem upper_unit (B : Matrix ι κ R) : +private theorem upper_unit (B : Matrix ι κ R) : IsUnit (fromBlocks (1 : Matrix ι ι R) B 0 (1 : Matrix κ κ R)) := by apply isUnit_iff_exists.mpr refine ⟨fromBlocks 1 (-B) 0 1, ?_, ?_⟩ <;> simp [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul] /-- A lower unitriangular block matrix is invertible. -/ -theorem lower_unit (C : Matrix κ ι R) : +private theorem lower_unit (C : Matrix κ ι R) : IsUnit (fromBlocks (1 : Matrix ι ι R) 0 C (1 : Matrix κ κ R)) := by apply isUnit_iff_exists.mpr refine ⟨fromBlocks 1 0 (-C) 1, ?_, ?_⟩ <;> @@ -201,7 +201,7 @@ theorem diag_unit_iff (A : Matrix ι ι R) (D : Matrix κ κ R) : simp [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul] /-- The Schur factorization of a block matrix with a zero corner and an invertible corner. -/ -theorem schur_factor (A A' : Matrix ι ι R) (B : Matrix ι κ R) (C : Matrix κ ι R) +private theorem schur_factor (A A' : Matrix ι ι R) (B : Matrix ι κ R) (C : Matrix κ ι R) (hAA' : A * A' = 1) (hA'A : A' * A = 1) : fromBlocks A B C 0 = fromBlocks 1 0 (C * A') 1 * fromBlocks A 0 0 (-C * A' * B) * diff --git a/Complexity/Computability/Circuit/Rational/Executable.lean b/Complexity/Computability/Circuit/Rational/Executable.lean index a97671227..6eaacfcda 100644 --- a/Complexity/Computability/Circuit/Rational/Executable.lean +++ b/Complexity/Computability/Circuit/Rational/Executable.lean @@ -62,7 +62,7 @@ def inputTables (n N e : ℕ) (x : Fin 3 → ℕ) : def normalizedEntry {d : ℕ} (A B : Table d) (den : ℤ) (i j : Fin d) : ℚ := Rat.divInt (determinant (tabulate ((denote A).updateCol i (fun r => denote B r j)))) den -lemma normalizedEntry_spec {d : ℕ} (A B : Table d) (hA : (denote A).det ≠ 0) (i j : Fin d) : +private lemma normalizedEntry_spec {d : ℕ} (A B : Table d) (hA : (denote A).det ≠ 0) (i j : Fin d) : normalizedEntry A B (determinant A) i j = (((denote A).map (Int.castRingHom ℚ))⁻¹ * (denote B).map (Int.castRingHom ℚ)) i j := by rw [normalizedEntry, determinant_eq, denote_tabulate, determinant_eq] @@ -91,7 +91,7 @@ def atPoint (n N e : ℕ) (x : Fin 3 → ℕ) : Option (Tuple n (Generator.matri let den := determinant (A.get 0) if den = 0 then none else some (tuple (normalized A den)) -lemma U_det_eq_zero (n N e : ℕ) (x : Fin 3 → ℕ) : +private lemma U_det_eq_zero (n N e : ℕ) (x : Fin 3 → ℕ) : (Generator.integralLift n N e x 0).det = 0 ↔ (Generator.rationalLift n N e x 0).det = 0 := by have he := congrArg Matrix.det (Generator.U_cast n N e x 0) rw [Matrix.det_smul] at he @@ -132,7 +132,7 @@ def output (n N e H : ℕ) : Output n where dimension_pos := Nat.mul_pos (CyclotomicRing.dimension_pos e) (CyclotomicRing.degree_pos e) tuples := (Generator.grid H).filterMap fun x => atPoint n N e (fun i => (x i).val + 1) -theorem output_spec (n N e H : ℕ) : output n N e H = Generator.output n N e H := by +private theorem output_spec (n N e H : ℕ) : output n N e H = Generator.output n N e H := by simp only [output, Generator.output, atPoint_spec] /-- The executable hitting list for the selected parameter values. -/ diff --git a/Complexity/Computability/Circuit/Rational/Generator.lean b/Complexity/Computability/Circuit/Rational/Generator.lean index 4867d9012..e18dfccd0 100644 --- a/Complexity/Computability/Circuit/Rational/Generator.lean +++ b/Complexity/Computability/Circuit/Rational/Generator.lean @@ -77,7 +77,7 @@ lemma mem_grid (H : ℕ) (x : Fin 3 → Fin H) : x ∈ grid H := by funext i fin_cases i <;> rfl -lemma grid_length (H : ℕ) : (grid H).length = H ^ 3 := by +private lemma grid_length (H : ℕ) : (grid H).length = H ^ 3 := by simp [grid, List.length_flatMap, pow_succ, Nat.mul_assoc] /-- The polynomial lift is evaluated over the exact rational quotient. -/ @@ -105,12 +105,12 @@ def output (n N e H : ℕ) : Output n where dimension_pos := Nat.mul_pos (CyclotomicRing.dimension_pos e) (CyclotomicRing.degree_pos e) tuples := (grid H).filterMap (fun x => atPoint n N e (fun i => (x i).val + 1)) -lemma length_output_le (n N e H : ℕ) : (output n N e H).tuples.length ≤ H ^ 3 := +private lemma length_output_le (n N e H : ℕ) : (output n N e H).tuples.length ≤ H ^ 3 := (List.length_filterMap_le _ _).trans_eq (grid_length H) /-- The actual emitted rational normalization is the homomorphic image of the quotient normalization. Consequently every original inverse occurrence is kept. -/ -lemma transfer {n N e : ℕ} (x : Fin 3 → ℕ) (f : Formula n) +private lemma transfer {n N e : ℕ} (x : Fin 3 → ℕ) (f : Formula n) (z : (Matrix (ZMod (CyclotomicRing.dimension e)) (ZMod (CyclotomicRing.dimension e)) (CyclotomicRing.R e))ˣ) (hz : (z : Matrix _ _ _) = specializedLift n N e x 0) @@ -134,7 +134,7 @@ lemma transfer {n N e : ℕ} (x : Fin 3 → ℕ) (f : Formula n) (specializedLift n N e x i.succ)) (regular e v) simpa only [map_mul, hzinv, rationalLift] using hh -lemma emitted {n N e H : ℕ} (x : Fin 3 → Fin H) +private lemma emitted {n N e H : ℕ} (x : Fin 3 → Fin H) (hz : IsUnit (specializedLift n N e (fun i => (x i).val + 1) 0)) : tupleAt n N e (fun i => (x i).val + 1) ∈ (output n N e H).tuples := by apply List.mem_filterMap.mpr @@ -152,18 +152,18 @@ open scoped BigOperators Rational.PolynomialHahn noncomputable section /-- The Hahn field containing the algebraic witnesses for the generator. -/ -abbrev WitnessField := HahnSeries QuantumLift.Exponents ℂ +private abbrev WitnessField := HahnSeries QuantumLift.Exponents ℂ /-- Embed the cyclotomic field into the Hahn witness field. -/ -def witnessEmbedding (e : ℕ) : CyclotomicRing.R e →+* WitnessField := +private def witnessEmbedding (e : ℕ) : CyclotomicRing.R e →+* WitnessField := (HahnSeries.C : ℂ →+* WitnessField).comp (CyclotomicRing.intoComplex e).toRingHom /-- Reindex the formula's pencil by its explicit finite dimension. -/ -def finPencil {n : ℕ} (f : Formula n) : +private def finPencil {n : ℕ} (f : Formula n) : Matrix (Fin (Fintype.card f.Index)) (Fin (Fintype.card f.Index)) (Affine.Form n) := (Formula.pencil f).reindex (Fintype.equivFin f.Index) (Fintype.equivFin f.Index) -lemma finPencil_unit {n : ℕ} {R : Type*} [Ring R] (c : ℚ →+* R) +private lemma finPencil_unit {n : ℕ} {R : Type*} [Ring R] (c : ℚ →+* R) (X : Fin n → R) (f : Formula n) : IsUnit ((finPencil f).map (Affine.eval c X)) ↔ IsUnit (Formula.realized c X f) := by let E := Matrix.reindexRingEquiv R (Fintype.equivFin f.Index) @@ -173,16 +173,17 @@ lemma finPencil_unit {n : ℕ} {R : Type*} [Ring R] (c : ℚ →+* R) · exact fun h => h.map E /-- A one-by-one constant pencil used to enforce normalization. -/ -def onePencil (n : ℕ) : Matrix (Fin 1) (Fin 1) (Affine.Form n) := fun _ _ => Affine.constant 1 +private def onePencil (n : ℕ) : + Matrix (Fin 1) (Fin 1) (Affine.Form n) := fun _ _ => Affine.constant 1 /-- Determinant polynomials whose simultaneous nonvanishing certifies a hit. -/ -def conditions {n : ℕ} (N e : ℕ) (f : Formula n) : +private def conditions {n : ℕ} (N e : ℕ) (f : Formula n) : List (MvPolynomial (Fin 3) (CyclotomicRing.R e)) := PencilCertificates.determinant (CyclotomicRing.character e) N (onePencil n) :: f.certificates.map fun h => PencilCertificates.determinant (CyclotomicRing.character e) N (finPencil h) -lemma condition_nonzero {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.nodeCount ≤ s) +private lemma condition_nonzero {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.nodeCount ≤ s) (hnz : Nonzero f) (hN : 1 ≤ N) (hMN : CyclotomicRing.dimension e = N + 2 * (n + 1) ^ 3 * (2 * s + 1)) (hM : (2 * s + 1) * (2 * (n + 1) ^ 3 * (2 * s + 1)) < CyclotomicRing.dimension e) : @@ -217,7 +218,7 @@ lemma condition_nonzero {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.n (2 * s + 1) d hb.1 hb.2 hN hMN hM hd Y exact (finPencil_unit _ _ h).mpr (hcert h hh) -lemma condition_degree {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.nodeCount ≤ s) : +private lemma condition_degree {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.nodeCount ≤ s) : (conditions N e f).length ≤ s + 2 ∧ ∀ p ∈ conditions N e f, p.totalDegree ≤ 3 * (2 * s + 1) * (CyclotomicRing.dimension e) ^ 2 := by refine ⟨?_, ?_⟩ @@ -231,7 +232,7 @@ lemma condition_degree {n s N e : ℕ} (hs : 1 ≤ s) (f : Formula n) (hf : f.no gcongr exact ((Formula.certificate_bounds f s hs hf).2 h hh).2) -lemma integer_grid {K : Type*} [Field K] [CharZero K] (P : List (MvPolynomial (Fin 3) K)) +private lemma integer_grid {K : Type*} [Field K] [CharZero K] (P : List (MvPolynomial (Fin 3) K)) (hP : ∀ p ∈ P, p ≠ 0) (d H : ℕ) (hd : ∀ p ∈ P, p.totalDegree ≤ d) (hH : P.length * d < H) : ∃ x : Fin 3 → Fin H, ∀ p ∈ P, eval (fun i => (((x i).val + 1 : ℕ) : K)) p ≠ 0 := by @@ -252,7 +253,7 @@ lemma integer_grid {K : Type*} [Field K] [CharZero K] (P : List (MvPolynomial (F have heq : (fun i => (((y i).val + 1 : ℕ) : K)) = x := funext hy simpa only [heq] using hxp p hp -lemma specialized_unit {K : Type*} [Field K] [CharZero K] {n q M N : ℕ} [NeZero M] +private lemma specialized_unit {K : Type*} [Field K] [CharZero K] {n q M N : ℕ} [NeZero M] (χ : AddChar (ZMod M) K) (L : Matrix (Fin q) (Fin q) (Affine.Form n)) (x : Fin 3 → K) (hx : eval x (PencilCertificates.determinant χ N L) ≠ 0) : IsUnit (L.map (Affine.homogeneous (algebraMap ℚ _) (fun i => @@ -266,7 +267,7 @@ lemma specialized_unit {K : Type*} [Field K] [CharZero K] {n q M N : ℕ} [NeZer rw [PencilCertificates.specialized] at hd simpa using hd.map (Matrix.compRingEquiv (Fin q) (ZMod M) K).symm -lemma onePencil_unit {K : Type*} [Field K] [CharZero K] {n : ℕ} +private lemma onePencil_unit {K : Type*} [Field K] [CharZero K] {n : ℕ} {ι : Type*} [Fintype ι] [DecidableEq ι] (rationalLift : Fin (n + 1) → Matrix ι ι K) (h : IsUnit ((onePencil n).map (Affine.homogeneous (algebraMap ℚ _) rationalLift))) : IsUnit (rationalLift 0) := by @@ -334,10 +335,10 @@ theorem threshold_pos (n s : ℕ) : 0 < rankBound s * delta n s := by simp only [rankBound, delta, w] positivity -theorem threshold_lt (n s : ℕ) : rankBound s * delta n s < ambientDimension n s := +private theorem threshold_lt (n s : ℕ) : rankBound s * delta n s < ambientDimension n s := Nat.lt_pow_succ_log_self (by omega) _ -theorem M_le (n s : ℕ) : ambientDimension n s ≤ 2 * (rankBound s * delta n s) := by +private theorem M_le (n s : ℕ) : ambientDimension n s ≤ 2 * (rankBound s * delta n s) := by unfold ambientDimension rw [pow_succ] have h := Nat.pow_log_le_self 2 (threshold_pos n s).ne' @@ -356,12 +357,12 @@ theorem N_pos (n s : ℕ) : 1 ≤ truncation n s := by unfold truncation omega -theorem M_eq (n s : ℕ) : ambientDimension n s = truncation n s + delta n s := by +private theorem M_eq (n s : ℕ) : ambientDimension n s = truncation n s + delta n s := by have hh := N_pos n s unfold truncation at * omega -theorem grid_large (n s : ℕ) : +private theorem grid_large (n s : ℕ) : (s + 2) * (3 * rankBound s * (ambientDimension n s) ^ 2) < gridSize n s := by have hp : 1 ≤ ambientDimension n s := by apply Nat.one_le_iff_ne_zero.mpr @@ -372,11 +373,11 @@ theorem grid_large (n s : ℕ) : unfold gridSize nlinarith [Nat.mul_le_mul_left (3 * (s + 2) * rankBound s) hpow] -theorem w_bound (n s : ℕ) : w n ≤ n + s + 1 := by unfold w; omega +private theorem w_bound (n s : ℕ) : w n ≤ n + s + 1 := by unfold w; omega -theorem B_bound (n s : ℕ) : rankBound s ≤ 2 * (n + s + 1) := by unfold rankBound; omega +private theorem B_bound (n s : ℕ) : rankBound s ≤ 2 * (n + s + 1) := by unfold rankBound; omega -theorem delta_bound (n s : ℕ) : delta n s ≤ 4 * (n + s + 1) ^ 4 := by +private theorem delta_bound (n s : ℕ) : delta n s ≤ 4 * (n + s + 1) ^ 4 := by calc delta n s ≤ 2 * (n + s + 1) ^ 3 * (2 * (n + s + 1)) := by unfold delta gcongr diff --git a/Complexity/Computability/Circuit/Rational/IntegralLift.lean b/Complexity/Computability/Circuit/Rational/IntegralLift.lean index f1af5cfdb..4ccc509cc 100644 --- a/Complexity/Computability/Circuit/Rational/IntegralLift.lean +++ b/Complexity/Computability/Circuit/Rational/IntegralLift.lean @@ -52,14 +52,14 @@ namespace Cslib.Circuits namespace Rational.CyclotomicRing open Polynomial Matrix Module -lemma root_degree (e : ℕ) : AdjoinRoot.root (modulus e) ^ degree e = -1 := by +private lemma root_degree (e : ℕ) : AdjoinRoot.root (modulus e) ^ degree e = -1 := by have h := AdjoinRoot.eval₂_root (modulus e) change Polynomial.eval₂ (AdjoinRoot.of (modulus e)) (AdjoinRoot.root (modulus e)) ((X : ℚ[X]) ^ degree e + 1) = 0 at h rw [Polynomial.eval₂_add, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_one] at h exact eq_neg_of_add_eq_zero_left h -lemma root_pow_reduce (e k : ℕ) : +private lemma root_pow_reduce (e k : ℕ) : AdjoinRoot.root (modulus e) ^ k = (-1 : R e) ^ (k / degree e) * (basis e ⟨k % degree e, Nat.mod_lt _ (degree_pos e)⟩) := by rw [basis_apply, ← root_degree, ← pow_mul, ← pow_add] @@ -69,7 +69,7 @@ lemma root_pow_reduce (e k : ℕ) : /-- Every regular-representation entry of a cyclotomic monomial is 0 or ±1. This also gives an explicit integral computation with a division and remainder. -/ -lemma rho_root_pow (e k : ℕ) (i j : Fin (degree e)) : +private lemma rho_root_pow (e k : ℕ) (i j : Fin (degree e)) : rho e (AdjoinRoot.root (modulus e) ^ k) i j = if (k + j.val) % degree e = i.val then (-1 : ℚ) ^ ((k + j.val) / degree e) else 0 := by rw [rho, Algebra.leftMulMatrix_eq_repr_mul, basis_apply, ← pow_add, root_pow_reduce] @@ -80,7 +80,7 @@ lemma rho_root_pow (e k : ℕ) (i j : Fin (degree e)) : congr 1 exact propext ⟨fun h => congrArg Fin.val h, fun h => Fin.ext h⟩ -lemma rho_character (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : +private lemma rho_character (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : rho e (character e a) i j = if (a.val + j.val) % degree e = i.val then (-1 : ℚ) ^ ((a.val + j.val) / degree e) else 0 := by @@ -90,12 +90,12 @@ lemma rho_character (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : def signedEntry (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : ℤ := if (a.val + j.val) % degree e = i.val then (-1 : ℤ) ^ ((a.val + j.val) / degree e) else 0 -lemma rho_character_integral (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : +private lemma rho_character_integral (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : rho e (character e a) i j = (signedEntry e a i j : ℚ) := by simp only [rho_character, signedEntry, Int.cast_ite, Int.cast_pow, Int.cast_neg, Int.cast_one, Int.cast_zero] -lemma signedEntry_abs (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : +private lemma signedEntry_abs (e : ℕ) (a : ZMod (dimension e)) (i j : Fin (degree e)) : |signedEntry e a i j| ≤ 1 := by unfold signedEntry split_ifs <;> simp [abs_pow] @@ -127,7 +127,7 @@ lemma coeff_bound (a : ℤ) (w M k j : ℕ) (hw : 1 ≤ w) (ha : |a| ≤ w) (hk (pow_le_pow_right₀ hw' (Nat.sub_le k j |>.trans hk)) _ = _ := by rw [← mul_pow]; congr 1; ring -lemma full_bound (M : ℕ) (a t : ℤ) (w H : ℕ) (hw : 1 ≤ w) (hH : 1 ≤ H) +private lemma full_bound (M : ℕ) (a t : ℤ) (w H : ℕ) (hw : 1 ≤ w) (hH : 1 ≤ H) (ha : |a| ≤ w) (ht : |t| ≤ H) (i j : Fin M) : |full M a t i j| ≤ (M : ℤ) * (2 * w : ℤ) ^ (2 * M) * (H : ℤ) ^ M := by unfold full @@ -150,21 +150,21 @@ lemma full_bound (M : ℕ) (a t : ℤ) (w H : ℕ) (hw : 1 ≤ w) (hH : 1 ≤ H) _ = _ := by rw [← pow_add]; simp [two_mul] _ = _ := by simp [mul_assoc] -lemma padded_bound (M N : ℕ) (a t : ℤ) (w H : ℕ) (hw : 1 ≤ w) (hH : 1 ≤ H) +private lemma padded_bound (M N : ℕ) (a t : ℤ) (w H : ℕ) (hw : 1 ≤ w) (hH : 1 ≤ H) (ha : |a| ≤ w) (ht : |t| ≤ H) (i j : Fin M) : |padded M N a t i j| ≤ (M : ℤ) * (2 * w : ℤ) ^ (2 * M) * (H : ℤ) ^ M := by by_cases h : j.val < N · simpa [padded, h] using full_bound M a t w H hw hH ha ht i j · simp only [padded, h, ite_false, abs_zero]; positivity -lemma full_cast {K : Type*} [Field K] (M : ℕ) (a t : ℤ) (i j : Fin M) : +private lemma full_cast {K : Type*} [Field K] (M : ℕ) (a t : ℤ) (i j : Fin M) : Polynomial.eval (t : K) (TestPolynomial.full M (a : K) i j) = (full M a t i j : K) := by simp only [TestPolynomial.full, full, coeff_X_add_C_pow, Polynomial.eval_finsetSum, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_pow, Polynomial.eval_X] simp only [Int.cast_sum, Int.cast_mul, Int.cast_pow, Int.cast_neg, Int.cast_natCast] -lemma padded_cast {K : Type*} [Field K] (M N : ℕ) (a t : ℤ) (i j : Fin M) : +private lemma padded_cast {K : Type*} [Field K] (M N : ℕ) (a t : ℤ) (i j : Fin M) : Polynomial.eval (t : K) (TestPolynomial.padded M N (a : K) i j) = (padded M N a t i j : K) := by by_cases h : j.val < N @@ -217,7 +217,7 @@ def entry (e : ℕ) (T : Matrix (ZMod (dimension e)) (ZMod (dimension e)) ℤ) T k (k - b) * signedEntry e (-a * k + a * u) i j * p ^ a.val * r ^ b.val else 0 -lemma entry_bound (e : ℕ) (T : Matrix (ZMod (dimension e)) (ZMod (dimension e)) ℤ) +private lemma entry_bound (e : ℕ) (T : Matrix (ZMod (dimension e)) (ZMod (dimension e)) ℤ) (p r : ℤ) (A H : ℕ) (hT : ∀ i j, |T i j| ≤ A) (hH : 1 ≤ H) (hp : |p| ≤ H) (hr : |r| ≤ H) (u v : ZMod (dimension e)) (i j : Fin (degree e)) : |entry e T p r u v i j| ≤ (dimension e : ℤ) ^ 3 * A * (H : ℤ) ^ (2 * dimension e) := by @@ -252,11 +252,11 @@ lemma entry_bound (e : ℕ) (T : Matrix (ZMod (dimension e)) (ZMod (dimension e) exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun k _ => hterm a b k)) _ = _ := by simp only [Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul]; ring -lemma rho_rat_mul (e : ℕ) (q : ℚ) (z : R e) (i j : Fin (degree e)) : +private lemma rho_rat_mul (e : ℕ) (q : ℚ) (z : R e) (i j : Fin (degree e)) : rho e (algebraMap ℚ (R e) q * z) i j = q * rho e z i j := by rw [← Algebra.smul_def, map_smul, Matrix.smul_apply, smul_eq_mul] -lemma rho_div_nat (e : ℕ) (z : R e) (i j : Fin (degree e)) : +private lemma rho_div_nat (e : ℕ) (z : R e) (i j : Fin (degree e)) : (dimension e : ℚ) * rho e ((dimension e : R e)⁻¹ * z) i j = rho e z i j := by have hc : (dimension e : R e)⁻¹ = algebraMap ℚ (R e) ((dimension e : ℚ)⁻¹) := by simp have hd : (dimension e : ℚ) ≠ 0 := by exact_mod_cast (dimension_pos e).ne' @@ -383,7 +383,7 @@ lemma U_bound (n N e H : ℕ) (x : Fin 3 → ℕ) (hH : 1 ≤ H) (hx : ∀ l, x CyclotomicRing.dimension e + 2 * CyclotomicRing.dimension e by omega, pow_add] ring -lemma scaled_normalization {d : ℕ} (A B : Mat d) (hA : A.det ≠ 0) (c : ℚ) (hc : c ≠ 0) : +private lemma scaled_normalization {d : ℕ} (A B : Mat d) (hA : A.det ≠ 0) (c : ℚ) (hc : c ≠ 0) : (c • A)⁻¹ * (c • B) = A⁻¹ * B := by let : Invertible c := invertibleOfNonzero hc have hi : (c • A)⁻¹ = c⁻¹ • A⁻¹ := by diff --git a/Complexity/Computability/Circuit/Rational/LaurentReduction.lean b/Complexity/Computability/Circuit/Rational/LaurentReduction.lean index 5867e2dc9..729cfb9c5 100644 --- a/Complexity/Computability/Circuit/Rational/LaurentReduction.lean +++ b/Complexity/Computability/Circuit/Rational/LaurentReduction.lean @@ -76,12 +76,12 @@ lemma integral_zero : Integral (0 : F K) := zero_mem _ lemma integral_one : Integral (1 : F K) := one_mem _ -lemma Integral.add {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x + y) := +private lemma Integral.add {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x + y) := add_mem hx hy lemma Integral.neg {x : F K} (hx : Integral x) : Integral (-x) := neg_mem hx -lemma Integral.sub {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x - y) := +private lemma Integral.sub {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x - y) := sub_mem hx hy lemma Integral.mul {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x * y) := @@ -93,7 +93,7 @@ lemma Integral.mul {x y : F K} (hx : Integral x) (hy : Integral y) : Integral (x lemma reduction_add (x y : F K) : reduction (x + y) = reduction x + reduction y := by simp [reduction] -lemma reduction_mul {x y : F K} (hx : Integral x) (hy : Integral y) : +private lemma reduction_mul {x y : F K} (hx : Integral x) (hy : Integral y) : reduction (x * y) = reduction x * reduction y := by obtain ⟨p, rfl⟩ := RingHom.mem_range.mp hx obtain ⟨q, rfl⟩ := RingHom.mem_range.mp hy @@ -105,7 +105,7 @@ lemma reduction_mul {x y : F K} (hx : Integral x) (hy : Integral y) : (LaurentSeries.coeff_coe_powerSeries s 0) rw [hc, hc, hc, map_mul] -lemma normalize_vector {ι : Type*} [Finite ι] (x : ι → F K) (hx : x ≠ 0) : +private lemma normalize_vector {ι : Type*} [Finite ι] (x : ι → F K) (hx : x ≠ 0) : ∃ (c : ι) (u : F K), u ≠ 0 ∧ (∀ i, Integral (u * x i)) ∧ u * x c = 1 := by classical have := Fintype.ofFinite ι @@ -276,7 +276,7 @@ namespace IntegralFrame variable {ι : Type*} {U : Submodule (F K) (ι → F K)} (b : IntegralFrame U) -lemma linearIndependent : LinearIndependent (F K) b.vector := by +private lemma linearIndependent : LinearIndependent (F K) b.vector := by classical rw [linearIndependent_iff'] intro s c hc j hj @@ -289,10 +289,10 @@ lemma vector_mem (j : Fin b.length) : b.vector j ∈ U := by /-- Full integral-lattice saturation: every integral member has integral basis coordinates, explicitly given by the constructed functionals. -/ -lemma integral_coordinates (x : ι → F K) (hx : IntegralVector x) : +private lemma integral_coordinates (x : ι → F K) (hx : IntegralVector x) : ∀ j, Integral (b.coordinate j x) := fun j => b.coordinate_integral j x hx -lemma sum_coordinates (x : ι → F K) (hx : x ∈ U) : +private lemma sum_coordinates (x : ι → F K) (hx : x ∈ U) : ∑ j, b.coordinate j x • b.vector j = x := by classical have hx := b.span_eq.ge hx @@ -302,31 +302,31 @@ lemma sum_coordinates (x : ι → F K) (hx : x ∈ U) : simp only [map_sum, map_smul, b.pairing, smul_eq_mul, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq, Finset.mem_univ, ite_true] -lemma length_eq_finrank : b.length = finrank (F K) U := by +private lemma length_eq_finrank : b.length = finrank (F K) U := by have hh := finrank_span_eq_card b.linearIndependent rw [b.span_eq] at hh simpa using hh.symm end IntegralFrame -lemma integral_C (a : K) : Integral (HahnSeries.C a : F K) := +private lemma integral_C (a : K) : Integral (HahnSeries.C a : F K) := RingHom.mem_range.mpr ⟨PowerSeries.C a, PowerSeries.coe_C a⟩ lemma reduction_C (a : K) : reduction (HahnSeries.C a : F K) = a := by simp [reduction, HahnSeries.C_apply] -lemma reduce_sum {ι τ : Type*} (s : Finset τ) (v : τ → (ι → F K)) : +private lemma reduce_sum {ι τ : Type*} (s : Finset τ) (v : τ → (ι → F K)) : reduce (∑ j ∈ s, v j) = ∑ j ∈ s, reduce (v j) := by ext i simp [reduce, reduction] -lemma reduce_smul {ι : Type*} {a : F K} {v : ι → F K} +private lemma reduce_smul {ι : Type*} {a : F K} {v : ι → F K} (ha : Integral a) (hv : IntegralVector v) : reduce (a • v) = reduction a • reduce v := by ext i exact reduction_mul ha (hv i) -lemma reduce_C_smul {ι : Type*} (a : K) (v : ι → F K) : +private lemma reduce_C_smul {ι : Type*} (a : K) (v : ι → F K) : reduce ((HahnSeries.C a : F K) • v) = a • reduce v := by ext i change reduction (HahnSeries.C a * v i) = a * reduction (v i) @@ -387,7 +387,7 @@ lemma Integral.order_nonneg {x : F K} (hx : Integral x) : 0 ≤ x.order := by have hh : Valued.v x ≤ WithZero.exp (-(0 : ℤ)) := by simpa using hv exact (LaurentSeries.valuation_le_iff_coeff_lt_eq_zero K).mp hh -lemma Integral.order_eq_zero {x : F K} (hx : Integral x) (hr : reduction x ≠ 0) : +private lemma Integral.order_eq_zero {x : F K} (hx : Integral x) (hr : reduction x ≠ 0) : x.order = 0 := le_antisymm (HahnSeries.order_le_of_coeff_ne_zero hr) hx.order_nonneg @@ -408,7 +408,7 @@ lemma weightMap_injective {ι : Type*} (w : ι → ℕ) : /-- The key valuation step of order reversal: an integral normalized input having a nonzero low reduction cannot give a high leading output coefficient. -/ -lemma weighted_high_reduction_zero {ι : Type*} (w : ι → ℕ) (A : ℕ) +private lemma weighted_high_reduction_zero {ι : Type*} (w : ι → ℕ) (A : ℕ) (x : ι → F K) (hx : IntegralVector x) (hlow : ∃ j, w j ≤ A ∧ reduction (x j) ≠ 0) (c : F K) (hc : c ≠ 0) @@ -435,7 +435,7 @@ lemma weighted_high_reduction_zero {ι : Type*} (w : ι → ℕ) (A : ℕ) /-- Low coordinates detect reduction throughout U. This controls its full integral image lattice, not only the images of an arbitrary integral basis. -/ -theorem reduction_weighted_supported {ι : Type*} [Finite ι] +private theorem reduction_weighted_supported {ι : Type*} [Finite ι] (w : ι → ℕ) (A : ℕ) (U : Submodule (F K) (ι → F K)) (hdetect : ∀ x ∈ U, IntegralVector x → (∀ i, w i ≤ A → reduction (x i) = 0) → reduce x = 0) @@ -463,7 +463,7 @@ theorem reduction_weighted_supported {ι : Type*} [Finite ι] exact he ▸ weighted_high_reduction_zero w A (u • x) hnI' hd u⁻¹ (inv_ne_zero hu) (he.symm ▸ hyI) -lemma exists_independent_subfamily {V : Type*} [AddCommGroup V] [Module K V] +private lemma exists_independent_subfamily {V : Type*} [AddCommGroup V] [Module K V] {h : ℕ} (v : Fin h → V) : ∃ (k : ℕ) (a : Fin k → Fin h), Function.Injective a ∧ Submodule.span K (Set.range (v ∘ a)) = Submodule.span K (Set.range v) ∧ @@ -484,7 +484,7 @@ lemma exists_independent_subfamily {V : Type*} [AddCommGroup V] [Module K V] rw [he, hs] /-- Restrict an integral frame to a selected family of basis vectors. -/ -def IntegralFrame.subframe {ι : Type*} {U : Submodule (F K) (ι → F K)} +private def IntegralFrame.subframe {ι : Type*} {U : Submodule (F K) (ι → F K)} (b : IntegralFrame U) {k : ℕ} (a : Fin k → Fin b.length) (ha : Function.Injective a) : IntegralFrame (Submodule.span (F K) (Set.range (b.vector ∘ a))) where @@ -507,7 +507,7 @@ lemma reducedSubspace_mono {ι : Type*} {U V : Submodule (F K) (ι → F K)} /-- Choose an integral-lattice subspace on whose reduction a specified projection is injective, of dimension equal to that projection's rank. -/ -theorem exists_projection_subspace {ι : Type*} [Finite ι] +private theorem exists_projection_subspace {ι : Type*} [Finite ι] {V : Type*} [AddCommGroup V] [Module K V] (U : Submodule (F K) (ι → F K)) (P : (ι → K) →ₗ[K] V) : ∃ U' : Submodule (F K) (ι → F K), U' ≤ U ∧ @@ -600,16 +600,16 @@ lemma liftMap_apply (P : (ι → K) →ₗ[K] κ → K) (x : ι → F K) (j : κ liftMap P x j = ∑ i, HahnSeries.C (LinearMap.toMatrix' P j i) * x i := rfl omit [Fintype τ] [DecidableEq τ] in -lemma liftMap_comp (P : (κ → K) →ₗ[K] τ → K) (Q : (ι → K) →ₗ[K] κ → K) : +private lemma liftMap_comp (P : (κ → K) →ₗ[K] τ → K) (Q : (ι → K) →ₗ[K] κ → K) : liftMap (P ∘ₗ Q) = liftMap P ∘ₗ liftMap Q := by simp only [liftMap, LinearMap.toMatrix'_comp, Matrix.map_mul, Matrix.toLin'_mul] -lemma liftMap_id : liftMap (LinearMap.id : (ι → K) →ₗ[K] (ι → K)) = LinearMap.id := by +private lemma liftMap_id : liftMap (LinearMap.id : (ι → K) →ₗ[K] (ι → K)) = LinearMap.id := by simp only [liftMap, LinearMap.toMatrix'_id, Matrix.map_one _ (map_zero _) (map_one _), Matrix.toLin'_one] omit [Fintype κ] [DecidableEq κ] in -lemma liftMap_integral (P : (ι → K) →ₗ[K] (κ → K)) {x : ι → F K} +private lemma liftMap_integral (P : (ι → K) →ₗ[K] (κ → K)) {x : ι → F K} (hx : IntegralVector x) : IntegralVector (liftMap P x) := by intro j rw [liftMap_apply] @@ -618,7 +618,7 @@ lemma liftMap_integral (P : (ι → K) →ₗ[K] (κ → K)) {x : ι → F K} exact (integral_C _).mul (hx i) omit [Fintype κ] [DecidableEq κ] in -lemma reduction_liftMap (P : (ι → K) →ₗ[K] κ → K) (x : ι → F K) : +private lemma reduction_liftMap (P : (ι → K) →ₗ[K] κ → K) (x : ι → F K) : reduce (liftMap P x) = P (reduce x) := by have hc (a : K) (z : F K) : reduction (HahnSeries.C a * z) = a * reduction z := by rw [HahnSeries.C_mul_eq_smul]; rfl @@ -664,7 +664,7 @@ lemma integral_liftEquiv_iff (E : (ι → K) ≃ₗ[K] (κ → K)) (x : ι → F simpa using hh · exact liftMap_integral E.toLinearMap -lemma reducedSubspace_liftEquiv (E : (ι → K) ≃ₗ[K] (κ → K)) +private lemma reducedSubspace_liftEquiv (E : (ι → K) ≃ₗ[K] (κ → K)) (U : Submodule (F K) (ι → F K)) : reducedSubspace (U.map (liftEquiv E).toLinearMap) = (reducedSubspace U).map E.toLinearMap := by diff --git a/Complexity/Computability/Circuit/Rational/PaddedRank.lean b/Complexity/Computability/Circuit/Rational/PaddedRank.lean index afcadd246..3993eaca5 100644 --- a/Complexity/Computability/Circuit/Rational/PaddedRank.lean +++ b/Complexity/Computability/Circuit/Rational/PaddedRank.lean @@ -53,7 +53,7 @@ open scoped BigOperators noncomputable section variable {K : Type*} [Field K] -lemma polynomialMap_single (M : ℕ) (b : Fin M) : +private lemma polynomialMap_single (M : ℕ) (b : Fin M) : polynomialMap M (Pi.single b (1 : K)) = X ^ b.val := by ext j by_cases hj : j < M @@ -104,9 +104,9 @@ def padded (M N : ℕ) (a : K) : Matrix (Fin M) (Fin M) K[X] := /-- The original t indeterminate embeds into the fresh Laurent indeterminate. -/ def embed : K[X] →+* F K := Polynomial.eval₂RingHom HahnSeries.C (HahnSeries.single 1 1) -lemma embed_C (a : K) : embed (C a) = HahnSeries.C a := by simp [embed] +private lemma embed_C (a : K) : embed (C a) = HahnSeries.C a := by simp [embed] -lemma embed_X_pow (a : ℕ) : embed ((X : K[X]) ^ a) = HahnSeries.single (a : ℤ) 1 := by +private lemma embed_X_pow (a : ℕ) : embed ((X : K[X]) ^ a) = HahnSeries.single (a : ℤ) 1 := by simp [embed, HahnSeries.single_pow] lemma full_embed (M : ℕ) (a : K) : @@ -128,7 +128,7 @@ lemma full_embed (M : ℕ) (a : K) : simp only [weightMap, LinearMap.coe_mk, AddHom.coe_mk, hin] ring -lemma full_natDegree_le (M : ℕ) (a : K) (i j : Fin M) : +private lemma full_natDegree_le (M : ℕ) (a : K) (i j : Fin M) : (full M a i j).natDegree ≤ M - 1 := by apply natDegree_sum_le_of_forall_le intro r _ @@ -182,7 +182,7 @@ def extend (q M N : ℕ) : (Fin q × Fin N → F K) →ₗ[F K] (Fin q × Fin M map_smul' c f := by funext a; by_cases h : a.2.val < N <;> simp [h] omit [CharZero K] in -lemma extend_low (q M N : ℕ) (f : Fin q × Fin N → F K) (α : Fin q) (j : Fin M) : +private lemma extend_low (q M N : ℕ) (f : Fin q × Fin N → F K) (α : Fin q) (j : Fin M) : N ≤ ↑j → extend q M N f (α, j) = 0 := by intro hj simp [extend, not_lt.mpr hj] @@ -196,7 +196,7 @@ lemma extend_injective (q M N : ℕ) (hNM : N ≤ M) : simpa [extend, j.isLt] using hh omit [CharZero K] in -lemma padded_mulVec_low (M N : ℕ) (a : K) (f : Fin M → F K) +private lemma padded_mulVec_low (M N : ℕ) (a : K) (f : Fin M → F K) (hf : ∀ (j : Fin M), N ≤ ↑j → f j = 0) : (embed.mapMatrix (padded M N a)).mulVec f = testMap M a f := by rw [← Matrix.toLin'_toMatrix' (testMap M a), ← full_embed M a, Matrix.toLin'_apply] @@ -271,12 +271,12 @@ open scoped BigOperators noncomputable section variable {K E : Type*} [Field K] [Field E] -lemma map_taylor_coeff (φ : K →+* E) (a : K) (j r : ℕ) : +private lemma map_taylor_coeff (φ : K →+* E) (a : K) (j r : ℕ) : φ (((X + C a) ^ j : K[X]).coeff r) = (((X + C (φ a)) ^ j : E[X]).coeff r) := by rw [← Polynomial.coeff_map] simp -lemma full_map (φ : K →+* E) (M : ℕ) (a : K) (i j : Fin M) : +private lemma full_map (φ : K →+* E) (M : ℕ) (a : K) (i j : Fin M) : (full M a i j).map φ = full M (φ a) i j := by unfold full rw [Polynomial.map_sum] @@ -285,7 +285,7 @@ lemma full_map (φ : K →+* E) (M : ℕ) (a : K) (i j : Fin M) : simp only [Polynomial.map_mul, Polynomial.map_C, Polynomial.map_pow, Polynomial.map_X, map_mul] rw [map_taylor_coeff φ (-a), map_taylor_coeff φ a, map_neg] -lemma padded_map (φ : K →+* E) (M N : ℕ) (a : K) (i j : Fin M) : +private lemma padded_map (φ : K →+* E) (M N : ℕ) (a : K) (i j : Fin M) : (padded M N a i j).map φ = padded M N (φ a) i j := by by_cases hj : j.val < N <;> simp [padded, hj, full_map] diff --git a/Complexity/Computability/Circuit/Rational/QuantumMatrices.lean b/Complexity/Computability/Circuit/Rational/QuantumMatrices.lean index 2a18d0c7d..7e3221e3a 100644 --- a/Complexity/Computability/Circuit/Rational/QuantumMatrices.lean +++ b/Complexity/Computability/Circuit/Rational/QuantumMatrices.lean @@ -55,7 +55,7 @@ open scoped BigOperators noncomputable section variable {Γ R : Type*} [AddCommGroup Γ] [LinearOrder Γ] [IsOrderedAddMonoid Γ] [Ring R] -lemma coeff_mul_support_superset (x y : HahnSeries Γ R) (a : Γ) +private lemma coeff_mul_support_superset (x y : HahnSeries Γ R) (a : Γ) (s t : Set Γ) (hs : s.IsPWO) (ht : t.IsPWO) (hxs : x.support ⊆ s) (hyt : y.support ⊆ t) : (x * y).coeff a = ∑ ij ∈ Finset.antidiagonal hs ht a, @@ -84,7 +84,7 @@ omit [AddCommGroup Γ] [IsOrderedAddMonoid Γ] [Fintype ι] [DecidableEq ι] in (entry x i j).coeff a = x.coeff a i j := rfl omit [AddCommGroup Γ] [IsOrderedAddMonoid Γ] [Fintype ι] [DecidableEq ι] in -lemma entry_support (x : HahnSeries Γ (Matrix ι ι R)) (i j : ι) : +private lemma entry_support (x : HahnSeries Γ (Matrix ι ι R)) (i j : ι) : (entry x i j).support ⊆ x.support := by intro a ha change x.coeff a ≠ 0 diff --git a/Complexity/Computability/Circuit/Rational/QuantumSeries.lean b/Complexity/Computability/Circuit/Rational/QuantumSeries.lean index 9c3408cda..d7b4df62b 100644 --- a/Complexity/Computability/Circuit/Rational/QuantumSeries.lean +++ b/Complexity/Computability/Circuit/Rational/QuantumSeries.lean @@ -63,7 +63,7 @@ matrix coefficient ring. -/ def line (B : Γ → Rˣ) (g : Γ) : Submodule K R := K ∙ (B g : R) omit [LinearOrder Γ] [IsOrderedAddMonoid Γ] [Nontrivial R] in -lemma line_mul (B : Γ → Rˣ) +private lemma line_mul (B : Γ → Rˣ) (hB : ∀ (g h : Γ), ∃ c : K, (B g : R) * (B h : R) = c • (B (g + h) : R)) {g h : Γ} {x y : R} (hx : x ∈ line (K := K) B g) (hy : y ∈ line (K := K) B h) : x * y ∈ line (K := K) B (g + h) := by @@ -74,7 +74,7 @@ lemma line_mul (B : Γ → Rˣ) exact Submodule.mem_span_singleton.mpr ⟨a * b * c, rfl⟩ omit [AddCommGroup Γ] [LinearOrder Γ] [IsOrderedAddMonoid Γ] [Nontrivial R] in -lemma line_isUnit (B : Γ → Rˣ) {g : Γ} {x : R} (hx : x ∈ line (K := K) B g) (hne : x ≠ 0) : +private lemma line_isUnit (B : Γ → Rˣ) {g : Γ} {x : R} (hx : x ∈ line (K := K) B g) (hne : x ≠ 0) : IsUnit x := by obtain ⟨a, rfl⟩ := Submodule.mem_span_singleton.mp hx have ha : a ≠ 0 := by intro h; simp [h] at hne @@ -109,7 +109,7 @@ def coefficientRing (B : Γ → Rˣ) (h0 : B 0 = 1) rw [← heq] exact line_mul B hB (hx ij.1) (hy ij.2) -lemma coefficientRing_noZeroDivisors (B : Γ → Rˣ) (h0 : B 0 = 1) +private lemma coefficientRing_noZeroDivisors (B : Γ → Rˣ) (h0 : B 0 = 1) (hB : ∀ g h, ∃ c : K, (B g : R) * (B h : R) = c • (B (g + h) : R)) : NoZeroDivisors (coefficientRing B h0 hB) := by constructor @@ -144,7 +144,7 @@ open HahnSeries HahnSeries.SummableFamily Finset Function noncomputable section variable {Γ R : Type*} [AddCommGroup Γ] [LinearOrder Γ] [IsOrderedAddMonoid Γ] [Ring R] -theorem power_finite_co_support {x : R⟦Γ⟧} (hx : 0 < x.orderTop) (g : Γ) : +private theorem power_finite_co_support {x : R⟦Γ⟧} (hx : 0 < x.orderTop) (g : Γ) : Set.Finite {a | ((fun n ↦ x ^ n) a).coeff g ≠ 0} := by have hpwo : Set.IsPWO (⋃ n, support (x ^ n)) := isPWO_iUnion_support_powers (zero_le_orderTop_iff.mp <| le_of_lt hx) @@ -210,7 +210,7 @@ theorem coe_geometricPowers : ⇑(geometricPowers x) = HPow.hPow x := by simp [hx] include hx in -theorem embDomain_succ_smul_geometricPowers : +private theorem embDomain_succ_smul_geometricPowers : (x • geometricPowers x).embDomain ⟨Nat.succ, Nat.succ_injective⟩ = geometricPowers x - SummableFamily.ofFinsupp (Finsupp.single 0 1) := by apply SummableFamily.ext @@ -290,7 +290,7 @@ variable (B : Γ → Rˣ) (h0 : B 0 = 1) omit [LinearOrder Γ] [IsOrderedAddMonoid Γ] in include h0 hB in -lemma line_inv_unit {g : Γ} (u : Rˣ) (hu : ↑u ∈ line (K := K) B g) : +private lemma line_inv_unit {g : Γ} (u : Rˣ) (hu : ↑u ∈ line (K := K) B g) : ↑u⁻¹ ∈ line (K := K) B (-g) := by obtain ⟨a, ha⟩ := Submodule.mem_span_singleton.mp hu obtain ⟨c, hc⟩ := hB g (-g) @@ -349,7 +349,7 @@ lemma inverse_candidate_mem (x : HahnSeries Γ R) exact (coefficientRing B h0 hB).pow_mem hz i exact (coefficientRing B h0 hB).mul_mem (hsum_mem B h0 hB _ hpow) hv -lemma inverse_exists (x : coefficientRing B h0 hB) (hx : x ≠ 0) : +private lemma inverse_exists (x : coefficientRing B h0 hB) (hx : x ≠ 0) : ∃ y : coefficientRing B h0 hB, x * y = 1 := by have hx' : (x : HahnSeries Γ R) ≠ 0 := by intro h; apply hx; exact Subtype.ext h diff --git a/Complexity/Computability/Circuit/Rational/Rectangular.lean b/Complexity/Computability/Circuit/Rational/Rectangular.lean index 2f2952f01..b52ce6c04 100644 --- a/Complexity/Computability/Circuit/Rational/Rectangular.lean +++ b/Complexity/Computability/Circuit/Rational/Rectangular.lean @@ -135,13 +135,13 @@ def coefficientMatrix {q k : ℕ} (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) : Matrix (Fin q) (Fin k) F := fun α => b.equivFun (component (F := F) f α) -lemma span_component_top {q : ℕ} (f : Fin q → P) : +private lemma span_component_top {q : ℕ} (f : Fin q → P) : Submodule.span F (Set.range (component (F := F) f)) = ⊤ := by apply Submodule.map_injective_of_injective (componentSpace (F := F) f).injective_subtype rw [Submodule.map_span, ← Set.range_comp, Submodule.map_top, Submodule.range_subtype] rfl -lemma rank_coefficientMatrix {q k : ℕ} (f : Fin q → P) +private lemma rank_coefficientMatrix {q k : ℕ} (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) : (coefficientMatrix f b).rank = k := by have hs : Submodule.span F (Set.range (coefficientMatrix f b)) = ⊤ := by have hh := congrArg (Submodule.map b.equivFun.toLinearMap) (span_component_top f) @@ -153,7 +153,7 @@ lemma rank_coefficientMatrix {q k : ℕ} (f : Fin q → P) rw [hs] simp -lemma coefficientMatrix_expansion {q k : ℕ} (f : Fin q → P) +private lemma coefficientMatrix_expansion {q k : ℕ} (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) (α : Fin q) : ∑ j, (coefficientMatrix f b) α j • (b j : P) = f α := by simpa only [coefficientMatrix, Basis.equivFun_apply, Submodule.coe_sum, @@ -169,7 +169,7 @@ def concatMatrix {w q k : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (P : Matrix (Fin q) (Fin k) F) : Matrix (Fin q) (Fin w × Fin k) F := fun α ij => (A ij.1 * P) α ij.2 -lemma concat_row_relation {w q k : ℕ} +private lemma concat_row_relation {w q k : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (T : Fin w → P →ₗ[F] Q) (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) (hker : ∀ α, ∑ i, ∑ γ, A i α γ • T i (f γ) = 0) (α : Fin q) : @@ -185,7 +185,7 @@ lemma concat_row_relation {w q k : ℕ} coefficientMatrix_expansion] exact hker α -lemma rank_concat_lt {w q k : ℕ} +private lemma rank_concat_lt {w q k : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (T : Fin w → P →ₗ[F] Q) (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) (hker : ∀ α, ∑ i, ∑ γ, A i α γ • T i (f γ) = 0) @@ -208,7 +208,7 @@ lemma rank_concat_lt {w q k : ℕ} change (w - 1) * k < finrank F H.range at hex omega -lemma coefficient_image_le_concat {w q k : ℕ} +private lemma coefficient_image_le_concat {w q k : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (P : Matrix (Fin q) (Fin k) F) (i : Fin w) : (Submodule.span F (Set.range P.col)).map (A i).mulVecLin ≤ Submodule.span F (Set.range (concatMatrix A P).col) := by @@ -219,7 +219,7 @@ lemma coefficient_image_le_concat {w q k : ℕ} funext α simp [concatMatrix, Matrix.mulVec, Matrix.mul_apply, dotProduct] -lemma component_image_le_range {w q k : ℕ} (T : Fin w → P →ₗ[F] Q) +private lemma component_image_le_range {w q k : ℕ} (T : Fin w → P →ₗ[F] Q) (f : Fin q → P) (b : Basis (Fin k) F (componentSpace (F := F) f)) (i : Fin w) : (componentSpace (F := F) f).map (T i) ≤ (imageCombination T (fun j => (b j : P))).range := by @@ -265,7 +265,7 @@ def blockMatrix {w q e : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (X : Fin w → Matrix (Fin e) (Fin e) F) : Matrix (Fin q × Fin e) (Fin q × Fin e) F := ∑ i, A i ⊗ₖ X i -lemma blockMatrix_mulVec {w q e : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) +private lemma blockMatrix_mulVec {w q e : ℕ} (A : Fin w → Matrix (Fin q) (Fin q) F) (X : Fin w → Matrix (Fin e) (Fin e) F) (v : Fin e → Fin q → F) (α : Fin q) (β : Fin e) : (blockMatrix A X).mulVec (fun j => v j.2 j.1) (α, β) = blockEval A X v β α := by diff --git a/Complexity/Computability/Circuit/Rational/Runtime/Determinant.lean b/Complexity/Computability/Circuit/Rational/Runtime/Determinant.lean index 73b0305e6..e16436cac 100644 --- a/Complexity/Computability/Circuit/Rational/Runtime/Determinant.lean +++ b/Complexity/Computability/Circuit/Rational/Runtime/Determinant.lean @@ -211,14 +211,14 @@ lemma rowEntry_rowsOf {d : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) (i j : Fin d) : rowEntry (rowsOf A) i j = A i j := by simp [rowEntry, rowsOf, List.getD_eq_getElem?_getD] -lemma stagesRows_zero (A : List (List ℤ)) : stagesRows A 0 = squareRows A := rfl +private lemma stagesRows_zero (A : List (List ℤ)) : stagesRows A 0 = squareRows A := rfl -lemma stagesRows_succ (A : List (List ℤ)) (k : ℕ) : +private lemma stagesRows_succ (A : List (List ℤ)) (k : ℕ) : stagesRows A (k + 1) = stepRows A (stagesRows A k) := Function.iterate_succ_apply' _ _ _ /-- A tail of a range, summed as a list, is a tail sum over `Fin`. -/ -lemma sum_map_drop_range (d lo : ℕ) (f : ℕ → ℤ) : +private lemma sum_map_drop_range (d lo : ℕ) (f : ℕ → ℤ) : (((List.range d).drop lo).map f).sum = BirdDet.sumFrom d lo f := by induction lo using BirdDet.sumFrom_induct d with | step lo hlo ih => @@ -229,14 +229,14 @@ lemma sum_map_drop_range (d lo : ℕ) (f : ℕ → ℤ) : rw [BirdDet.sumFrom_stop d lo f hlo, List.drop_eq_nil_of_le (by simpa using hlo)] rfl -lemma sum_map_drop_range_fin {d : ℕ} (i : Fin d) (f : ℕ → ℤ) : +private lemma sum_map_drop_range_fin {d : ℕ} (i : Fin d) (f : ℕ → ℤ) : (((List.range d).drop (i.val + 1)).map f).sum = ∑ k ∈ Finset.Ioi i, f k.val := by rw [sum_map_drop_range, DeterminantAlgorithm.sumFrom_fin_tail] /-! ### Correctness -/ /-- The list stages agree with the Bird stages of the matrix denoted by the input. -/ -theorem rowEntry_stagesRows (A : List (List ℤ)) (k : ℕ) (i j : Fin A.length) : +private theorem rowEntry_stagesRows (A : List (List ℤ)) (k : ℕ) (i j : Fin A.length) : rowEntry (stagesRows A k) i j = ((BirdDet.Spec.stepEntry (ofRows A))^[k] (ofRows A)) i j := by induction k generalizing i j with @@ -293,7 +293,7 @@ theorem detRows_rowsOf_denote {d : ℕ} (A : DeterminantAlgorithm.Table d) : /-! ### Size bounds -/ -lemma natAbs_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) : +private lemma natAbs_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) : l.sum.natAbs ≤ l.length * C := by induction l with | nil => simp @@ -305,7 +305,7 @@ lemma natAbs_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) : _ = (l.length + 1) * C := by ring /-- Every prefix sum of a list is bounded by its length times a bound on its entries. -/ -lemma natAbs_take_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) (m : ℕ) : +private lemma natAbs_take_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) (m : ℕ) : (l.take m).sum.natAbs ≤ l.length * C := (natAbs_sum_le fun x hx => h x (List.mem_of_mem_take hx)).trans (Nat.mul_le_mul_right _ (List.length_take_le' _ _)) @@ -338,12 +338,12 @@ lemma exists_rowEntry_eq {rows : List (List ℤ)} {row : List ℤ} {z : ℤ} (hr obtain ⟨j, hj, rfl⟩ := List.getElem_of_mem hz exact ⟨i, j, by simp [rowEntry, List.getD_eq_getElem?_getD, hi, hj]⟩ -lemma length_traceTerms_le (A F : List (List ℤ)) (i : ℕ) : +private lemma length_traceTerms_le (A F : List (List ℤ)) (i : ℕ) : (traceTerms A F i).length ≤ A.length := by simp only [traceTerms, List.length_map, List.length_drop, List.length_range] omega -lemma length_productTerms_le (A F : List (List ℤ)) (i j : ℕ) : +private lemma length_productTerms_le (A F : List (List ℤ)) (i j : ℕ) : (productTerms A F i j).length ≤ A.length := by simp only [productTerms, List.length_map, List.length_drop, List.length_range] omega @@ -406,7 +406,7 @@ private lemma trace_mul_le (hA : ∀ i j, (rowEntry A i j).natAbs < 2 ^ b) (hA i j).le /-- The trace product computed in one stage obeys the next stage's bound. -/ -theorem natAbs_traceTerms_sum_mul_lt (hA : ∀ i j, (rowEntry A i j).natAbs < 2 ^ b) +private theorem natAbs_traceTerms_sum_mul_lt (hA : ∀ i j, (rowEntry A i j).natAbs < 2 ^ b) (hF : ∀ i j, (rowEntry F i j).natAbs < 2 ^ e) (i j : ℕ) : ((traceTerms A F i).sum * rowEntry A i j).natAbs < 2 ^ (e + (1 + A.length + b)) := ((trace_mul_le hA hF i j).trans_lt (length_mul_lt A b e)).trans_le (half_le_bound A b e) @@ -521,7 +521,7 @@ lemma length_of_mem_stagesRows {A : List (List ℤ)} {k : ℕ} {row : List ℤ} | zero => exact length_of_mem_tabulateRows hrow | succ k => rw [stagesRows_succ] at hrow; exact length_of_mem_tabulateRows hrow -lemma intBits_le_length_encList {A : List (List ℤ)} {row : List ℤ} (hrow : row ∈ A) +private lemma intBits_le_length_encList {A : List (List ℤ)} {row : List ℤ} (hrow : row ∈ A) {z : ℤ} (hz : z ∈ row) : intBits z ≤ (encList (encList encIntBin) A).length + 1 := by rw [intBits_eq_length_encIntBin] exact ((length_le_encList_of_mem encIntBin hz).trans @@ -678,7 +678,7 @@ theorem computableInPolyTime_stagesRows {A : α → List (List ℤ)} {k : α → (polyBounded_stageTableBound hA.polyBounded_length hk.polyBounded) fun x _ hi => length_encList_stagesRows_le (A x) hi) -lemma detRows_eq_ite (A : List (List ℤ)) : +private lemma detRows_eq_ite (A : List (List ℤ)) : detRows A = if A.isEmpty then 1 else (-1) ^ (A.length - 1) * rowEntry (stagesRows A (A.length - 1)) 0 0 := by diff --git a/Complexity/Computability/Circuit/Rational/Runtime/Encode.lean b/Complexity/Computability/Circuit/Rational/Runtime/Encode.lean index f8d61e22f..29a06d1a4 100644 --- a/Complexity/Computability/Circuit/Rational/Runtime/Encode.lean +++ b/Complexity/Computability/Circuit/Rational/Runtime/Encode.lean @@ -125,7 +125,7 @@ theorem divInt_sign (a b : ℤ) (hb : b ≠ 0) : simp [not_lt_of_gt hpa, not_lt_of_gt hpb, not_lt_of_ge hp.le] /-- Reduced numerator magnitude of `Rat.divInt a b` for arbitrary integers `a, b`. -/ -theorem divInt_num_abs_eq (a b : ℤ) : +private theorem divInt_num_abs_eq (a b : ℤ) : (Rat.divInt a b).num.natAbs = if b = 0 then 0 else a.natAbs / Nat.gcd a.natAbs b.natAbs := by by_cases hb : b = 0 @@ -133,7 +133,7 @@ theorem divInt_num_abs_eq (a b : ℤ) : · simp [hb, divInt_num_abs a b hb] /-- Reduced denominator of `Rat.divInt a b` for arbitrary integers `a, b`. -/ -theorem divInt_den_eq (a b : ℤ) : +private theorem divInt_den_eq (a b : ℤ) : (Rat.divInt a b).den = if b = 0 then 1 else b.natAbs / Nat.gcd a.natAbs b.natAbs := by by_cases hb : b = 0 @@ -141,7 +141,7 @@ theorem divInt_den_eq (a b : ℤ) : · simp [hb, divInt_den a b hb] /-- Sign bit of `Rat.divInt a b` for arbitrary integers `a, b`. -/ -theorem divInt_sign_eq (a b : ℤ) : +private theorem divInt_sign_eq (a b : ℤ) : decide ((Rat.divInt a b).num < 0) = if a = 0 then false else if b = 0 then false else (decide (a < 0) ^^ decide (b < 0)) := by by_cases hb : b = 0 diff --git a/Complexity/Computability/Circuit/Rational/Runtime/Lift.lean b/Complexity/Computability/Circuit/Rational/Runtime/Lift.lean index 1c494face..124d766a5 100644 --- a/Complexity/Computability/Circuit/Rational/Runtime/Lift.lean +++ b/Complexity/Computability/Circuit/Rational/Runtime/Lift.lean @@ -66,7 +66,8 @@ namespace Rational /-! ### Magnitude bounds -/ -lemma natAbs_pow_le {z : ℤ} {H : ℕ} (hH : 1 ≤ H) (hz : z.natAbs ≤ H) {q M : ℕ} (hq : q ≤ M) : +private lemma natAbs_pow_le {z : ℤ} {H : ℕ} (hH : 1 ≤ H) (hz : z.natAbs ≤ H) {q M : ℕ} + (hq : q ≤ M) : (z ^ q).natAbs ≤ H ^ M := by rw [Int.natAbs_pow] exact (Nat.pow_le_pow_left hz q).trans (Nat.pow_le_pow_right hH hq) @@ -78,7 +79,8 @@ include hw hc /-- The coefficients of `(X + c) ^ k` are at most `(2 * w) ^ k` in absolute value, by `IntegralTest.coeff_bound`. -/ -theorem natAbs_getD_coeffRow_le (k i : ℕ) : ((coeffRow c k).getD i 0).natAbs ≤ (2 * w) ^ k := by +private theorem natAbs_getD_coeffRow_le (k i : ℕ) : + ((coeffRow c k).getD i 0).natAbs ≤ (2 * w) ^ k := by have h := IntegralTest.coeff_bound c w k k i hw (by rw [Int.abs_eq_natAbs]; exact_mod_cast hc) le_rfl rw [← getD_coeffRow, Int.abs_eq_natAbs] at h @@ -86,7 +88,7 @@ theorem natAbs_getD_coeffRow_le (k i : ℕ) : ((coeffRow c k).getD i 0).natAbs /-- The values computed by the shift-and-add step from `coeffRow c k`: the shifted coefficient, the scaled coefficient and their sum. -/ -theorem natAbs_shiftAdd_le (k i : ℕ) : +private theorem natAbs_shiftAdd_le (k i : ℕ) : ((0 :: coeffRow c k).getD i 0).natAbs ≤ (2 * w) ^ (k + 1) ∧ (c * (coeffRow c k).getD i 0).natAbs ≤ (2 * w) ^ (k + 1) ∧ ((0 :: coeffRow c k).getD i 0 + c * (coeffRow c k).getD i 0).natAbs ≤ @@ -103,7 +105,7 @@ theorem natAbs_shiftAdd_le (k i : ℕ) : · rw [← getD_shiftAddRow, ← coeffRow_succ] exact natAbs_getD_coeffRow_le hw hc (k + 1) i -theorem natAbs_rowEntry_coeffRows_le (M k i : ℕ) : +private theorem natAbs_rowEntry_coeffRows_le (M k i : ℕ) : (rowEntry (coeffRows c M) k i).natAbs ≤ (2 * w) ^ M := by rw [rowEntry_coeffRows] split_ifs with h @@ -118,7 +120,7 @@ variable {M : ℕ} {a t : ℤ} {w H : ℕ} (hw : 1 ≤ w) (ha : a.natAbs ≤ w) (ht : t.natAbs ≤ H) include hw ha in -theorem natAbs_coeffProduct_le (k u v q : ℕ) : +private theorem natAbs_coeffProduct_le (k u v q : ℕ) : (rowEntry (coeffRows (-a) M) k u * rowEntry (coeffRows a M) v q).natAbs ≤ (2 * w) ^ (2 * M) := by rw [Int.natAbs_mul, show 2 * M = M + M by omega, pow_add] @@ -127,21 +129,21 @@ theorem natAbs_coeffProduct_le (k u v q : ℕ) : include hw ha hH ht -theorem natAbs_testTerm_le {q : ℕ} (hq : q ≤ M) (u v : ℕ) : +private theorem natAbs_testTerm_le {q : ℕ} (hq : q ≤ M) (u v : ℕ) : (testTerm M (coeffRows (-a) M) (coeffRows a M) t u v q).natAbs ≤ (2 * w) ^ (2 * M) * H ^ M := by rw [testTerm, Int.natAbs_mul] exact Nat.mul_le_mul (natAbs_coeffProduct_le hw ha ..) (natAbs_pow_le hH ht hq) /-- Every prefix sum of the summands of a Taylor entry. -/ -theorem natAbs_testTerms_take_sum_le (u v m : ℕ) : +private theorem natAbs_testTerms_take_sum_le (u v m : ℕ) : ((testTerms M (coeffRows (-a) M) (coeffRows a M) t u v).take m).sum.natAbs ≤ M * ((2 * w) ^ (2 * M) * H ^ M) := by refine natAbs_take_sum_le_of_length (by simp [testTerms]) (fun z hz => ?_) m obtain ⟨q, hq, rfl⟩ := List.mem_map.mp hz exact natAbs_testTerm_le hw ha hH ht (List.mem_range.mp hq).le u v -theorem natAbs_rowEntry_testRows_le (N u v : ℕ) : +private theorem natAbs_rowEntry_testRows_le (N u v : ℕ) : (rowEntry (testRows M N a t) u v).natAbs ≤ M * ((2 * w) ^ (2 * M) * H ^ M) := by rw [testRows, rowEntry_tabulateRows] split_ifs @@ -154,7 +156,7 @@ theorem natAbs_rowEntry_testRows_le (N u v : ℕ) : end TestBounds -lemma natAbs_signedCoeff_le (Dg z i j : ℕ) : (signedCoeff Dg z i j).natAbs ≤ 1 := by +private lemma natAbs_signedCoeff_le (Dg z i j : ℕ) : (signedCoeff Dg z i j).natAbs ≤ 1 := by unfold signedCoeff split_ifs <;> simp [Int.natAbs_pow] @@ -165,47 +167,47 @@ variable {M Dg : ℕ} {T : List (List ℤ)} {p r : ℤ} {A H : ℕ} include hT /-- The partial products of a lift term, for any indices. -/ -theorem natAbs_liftPartial_le (k l z i j : ℕ) : +private theorem natAbs_liftPartial_le (k l z i j : ℕ) : (rowEntry T k l * signedCoeff Dg z i j).natAbs ≤ A := by rw [Int.natAbs_mul] simpa using Nat.mul_le_mul (hT k l) (natAbs_signedCoeff_le Dg z i j) include hH hp -theorem natAbs_liftPartial_pow_le (k l z i j : ℕ) {α : ℕ} (hα : α ≤ M) : +private theorem natAbs_liftPartial_pow_le (k l z i j : ℕ) {α : ℕ} (hα : α ≤ M) : (rowEntry T k l * signedCoeff Dg z i j * p ^ α).natAbs ≤ A * H ^ M := by rw [Int.natAbs_mul] exact Nat.mul_le_mul (natAbs_liftPartial_le hT ..) (natAbs_pow_le hH hp hα) include hr -theorem natAbs_liftTerm_le {α : ℕ} (hα : α < M) (u v i j κ : ℕ) : +private theorem natAbs_liftTerm_le {α : ℕ} (hα : α < M) (u v i j κ : ℕ) : (liftTerm M Dg T p r u v i j α κ).natAbs ≤ A * H ^ (2 * M) := by rw [liftTerm, Int.natAbs_mul, show 2 * M = M + M by omega, pow_add, ← Nat.mul_assoc] exact Nat.mul_le_mul (natAbs_liftPartial_pow_le hT hH hp _ _ _ _ _ hα.le) (natAbs_pow_le hH hr (Nat.mod_lt _ (by omega)).le) /-- Every prefix sum of an inner sum of a lift entry. -/ -theorem natAbs_liftTerms_take_sum_le {α : ℕ} (hα : α < M) (u v i j m : ℕ) : +private theorem natAbs_liftTerms_take_sum_le {α : ℕ} (hα : α < M) (u v i j m : ℕ) : ((liftTerms M Dg T p r u v i j α).take m).sum.natAbs ≤ M * (A * H ^ (2 * M)) := by refine natAbs_take_sum_le_of_length (by simp [liftTerms]) (fun z hz => ?_) m obtain ⟨κ, -, rfl⟩ := List.mem_map.mp hz exact natAbs_liftTerm_le hT hH hp hr hα u v i j κ /-- Every prefix sum of the outer sum of a lift entry. -/ -theorem natAbs_liftSums_take_sum_le (u v i j m : ℕ) : +private theorem natAbs_liftSums_take_sum_le (u v i j m : ℕ) : ((liftSums M Dg T p r u v i j).take m).sum.natAbs ≤ M * (M * (A * H ^ (2 * M))) := by refine natAbs_take_sum_le_of_length (by simp [liftSums]) (fun z hz => ?_) m obtain ⟨α, hα, rfl⟩ := List.mem_map.mp hz have h := natAbs_liftTerms_take_sum_le (Dg := Dg) hT hH hp hr (List.mem_range.mp hα) u v i j M rwa [List.take_of_length_le (by simp [liftTerms])] at h -theorem natAbs_liftEntry_le (u v i j : ℕ) : +private theorem natAbs_liftEntry_le (u v i j : ℕ) : (liftEntry M Dg T p r u v i j).natAbs ≤ M * (M * (A * H ^ (2 * M))) := by have h := natAbs_liftSums_take_sum_le (M := M) (Dg := Dg) hT hH hp hr u v i j M rwa [List.take_of_length_le (by simp [liftSums])] at h -theorem natAbs_rowEntry_liftTable_le (i j : ℕ) : +private theorem natAbs_rowEntry_liftTable_le (i j : ℕ) : (rowEntry (liftTable M Dg T p r) i j).natAbs ≤ M * (M * (A * H ^ (2 * M))) := by rw [liftTable, rowEntry_tabulateRows] split_ifs @@ -228,7 +230,7 @@ lemma liftBits_parameters (n s : ℕ) : rfl /-- At the generator's parameters, the bit-length budget is polynomial in `n + s + 1`. -/ -theorem liftBits_bound (n s : ℕ) : +private theorem liftBits_bound (n s : ℕ) : liftBits n (Parameters.ambientDimension n s) (Parameters.gridSize n s) ≤ PolynomialBounds.logConstant * (n + s + 1) ^ 22 + 2 := by rw [liftBits_parameters] @@ -236,7 +238,7 @@ theorem liftBits_bound (n s : ℕ) : /-- Every value of magnitude at most `M ^ 3 * (2 * (n + 1)) ^ (2 * M) * H ^ (3 * M)` fits in the budget. -/ -theorem intBits_le_liftBits {n M H : ℕ} {z : ℤ} +private theorem intBits_le_liftBits {n M H : ℕ} {z : ℤ} (hz : z.natAbs ≤ M ^ 3 * (2 * (n + 1)) ^ (2 * M) * H ^ (3 * M)) : intBits z ≤ liftBits n M H := by have hM : M ^ 3 ≤ 2 ^ (3 * M) := by @@ -261,7 +263,7 @@ theorem intBits_le_liftBits {n M H : ℕ} {z : ℤ} exact (intBits_le_iff _ _).mpr hlt /-- Each factor of the magnitude bound can be weakened. -/ -lemma le_liftMagnitude {M w H i j k : ℕ} (hM : 1 ≤ M) (hw : 1 ≤ w) (hH : 1 ≤ H) (hi : i ≤ 3) +private lemma le_liftMagnitude {M w H i j k : ℕ} (hM : 1 ≤ M) (hw : 1 ≤ w) (hH : 1 ≤ H) (hi : i ≤ 3) (hj : j ≤ 2 * M) (hk : k ≤ 3 * M) : M ^ i * (2 * w) ^ j * H ^ k ≤ M ^ 3 * (2 * w) ^ (2 * M) * H ^ (3 * M) := by gcongr diff --git a/Complexity/Computability/Circuit/Rational/Runtime/Lift/Defs.lean b/Complexity/Computability/Circuit/Rational/Runtime/Lift/Defs.lean index 5ecb425ec..cd2119e33 100644 --- a/Complexity/Computability/Circuit/Rational/Runtime/Lift/Defs.lean +++ b/Complexity/Computability/Circuit/Rational/Runtime/Lift/Defs.lean @@ -77,7 +77,7 @@ open Polynomial /-! ### Index bridges -/ -lemma val_finEquiv {m : ℕ} [NeZero m] (i : Fin m) : (ZMod.finEquiv m i).val = i.val := by +private lemma val_finEquiv {m : ℕ} [NeZero m] (i : Fin m) : (ZMod.finEquiv m i).val = i.val := by cases m with | zero => exact (NeZero.ne 0 rfl).elim | succ m => rfl @@ -87,13 +87,13 @@ lemma val_finEquiv_symm {m : ℕ} [NeZero m] (z : ZMod m) : rw [← val_finEquiv, RingEquiv.apply_symm_apply] /-- A sum over `List.range m` is a sum over `Fin m`. -/ -lemma sum_range_eq_sum_fin {A : Type*} [AddCommMonoid A] (m : ℕ) (f : ℕ → A) : +private lemma sum_range_eq_sum_fin {A : Type*} [AddCommMonoid A] (m : ℕ) (f : ℕ → A) : ((List.range m).map f).sum = ∑ i : Fin m, f i := by rw [← List.map_coe_finRange_eq_range, List.map_map, ← List.ofFn_eq_map, List.sum_ofFn] rfl /-- A sum over `List.range m` is a sum over the residues modulo `m`. -/ -lemma sum_range_eq_sum_zmod {A : Type*} [AddCommMonoid A] (m : ℕ) [NeZero m] (f : ℕ → A) : +private lemma sum_range_eq_sum_zmod {A : Type*} [AddCommMonoid A] (m : ℕ) [NeZero m] (f : ℕ → A) : ((List.range m).map f).sum = ∑ z : ZMod m, f z.val := by rw [sum_range_eq_sum_fin] exact Fintype.sum_equiv (ZMod.finEquiv m).toEquiv _ _ fun i => by @@ -101,14 +101,14 @@ lemma sum_range_eq_sum_zmod {A : Type*} [AddCommMonoid A] (m : ℕ) [NeZero m] ( rw [val_finEquiv] /-- Residue subtraction on values, without truncated subtraction below zero. -/ -lemma val_sub_eq_mod {m : ℕ} [NeZero m] (u v : ZMod m) : +private lemma val_sub_eq_mod {m : ℕ} [NeZero m] (u v : ZMod m) : (u - v).val = (u.val + m - v.val) % m := by have hv := v.val_lt rw [← ZMod.val_natCast, Nat.cast_sub (by omega), Nat.cast_add, ZMod.natCast_self, ZMod.natCast_zmod_val, ZMod.natCast_zmod_val, add_zero] /-- The residue `-a * k + a * u` of the lift formula, on values. -/ -lemma val_neg_mul_add_mul_eq_mod {m : ℕ} [NeZero m] (a u k : ZMod m) : +private lemma val_neg_mul_add_mul_eq_mod {m : ℕ} [NeZero m] (a u k : ZMod m) : (-a * k + a * u).val = a.val * (u.val + m - k.val) % m := by have hk := k.val_lt rw [← ZMod.val_natCast, Nat.cast_mul, Nat.cast_sub (by omega), Nat.cast_add, ZMod.natCast_self, @@ -239,7 +239,7 @@ theorem testEntry_eq (M N : ℕ) (a t : ℤ) (u v : Fin M) : show M - (q.val + 1) = M - 1 - q by omega] · rfl -theorem rowEntry_testRows (M N : ℕ) (a t : ℤ) (u v : Fin M) : +private theorem rowEntry_testRows (M N : ℕ) (a t : ℤ) (u v : Fin M) : rowEntry (testRows M N a t) u v = IntegralTest.padded M N a t u v := by rw [testRows, rowEntry_tabulateRows, ite_eq_left ⟨u.isLt, v.isLt⟩, testEntry_eq] @@ -249,7 +249,7 @@ theorem testRows_eq (M N : ℕ) (a t : ℤ) : tabulateRows_eq_rowsOf _ _ (testEntry_eq M N a t) /-- The Taylor rows, read at residues, are the residue-indexed `Generator.integerTest`. -/ -theorem rowEntry_testRows_integerTest (N e : ℕ) (a t : ℤ) +private theorem rowEntry_testRows_integerTest (N e : ℕ) (a t : ℤ) (u v : ZMod (CyclotomicRing.dimension e)) : rowEntry (testRows (CyclotomicRing.dimension e) N a t) u.val v.val = Generator.integerTest N e a t u v := by @@ -295,7 +295,7 @@ residues and cyclotomic degree `Dg`. -/ def liftRows (n N M Dg t p r : ℕ) : List (List (List ℤ)) := (List.range (n + 1)).map fun a : ℕ => liftTable M Dg (testRows M N a t) p r -lemma signedCoeff_eq (e : ℕ) (z : ZMod (CyclotomicRing.dimension e)) +private lemma signedCoeff_eq (e : ℕ) (z : ZMod (CyclotomicRing.dimension e)) (i j : Fin (CyclotomicRing.degree e)) : signedCoeff (CyclotomicRing.degree e) z.val i j = CyclotomicRing.signedEntry e z i j := rfl @@ -321,7 +321,7 @@ theorem liftEntry_eq (e : ℕ) {T : List (List ℤ)} ← val_neg_mul_add_mul_eq_mod α u κ, hT, signedCoeff_eq] /-- The integer lift entry of `Generator.integralLift`, on the residues of the test rows. -/ -theorem liftEntry_testRows (N e : ℕ) (a t p r : ℤ) (u v : ZMod (CyclotomicRing.dimension e)) +private theorem liftEntry_testRows (N e : ℕ) (a t p r : ℤ) (u v : ZMod (CyclotomicRing.dimension e)) (i j : Fin (CyclotomicRing.degree e)) : liftEntry (CyclotomicRing.dimension e) (CyclotomicRing.degree e) (testRows (CyclotomicRing.dimension e) N a t) p r u.val v.val i j = @@ -329,7 +329,7 @@ theorem liftEntry_testRows (N e : ℕ) (a t p r : ℤ) (u v : ZMod (CyclotomicRi liftEntry_eq e (rowEntry_testRows_integerTest N e a t) p r u v i j /-- The entries of a lift table are the entries of `Generator.integralLift`. -/ -theorem liftEntry_coordinate (n N e : ℕ) (x : Fin 3 → ℕ) (a : Fin (n + 1)) +private theorem liftEntry_coordinate (n N e : ℕ) (x : Fin 3 → ℕ) (a : Fin (n + 1)) (i j : Fin (Generator.matrixDimension e)) : liftEntry (CyclotomicRing.dimension e) (CyclotomicRing.degree e) (testRows (CyclotomicRing.dimension e) N a (x 0)) (x 1) (x 2) diff --git a/Complexity/Computability/Circuit/Rational/Runtime/Point.lean b/Complexity/Computability/Circuit/Rational/Runtime/Point.lean index 7b2fd4470..8537b3fe7 100644 --- a/Complexity/Computability/Circuit/Rational/Runtime/Point.lean +++ b/Complexity/Computability/Circuit/Rational/Runtime/Point.lean @@ -164,7 +164,7 @@ theorem tupleWord_eq {n d : ℕ} (A : Vector (DeterminantAlgorithm.Table d) (n + /-- `pointWordOfTables` on the row lists of `A` tests `determinant (A.get 0) = 0` and encodes the normalized tuple when nonsingular. -/ -theorem pointWordOfTables_eq {n d : ℕ} (A : Vector (DeterminantAlgorithm.Table d) (n + 1)) : +private theorem pointWordOfTables_eq {n d : ℕ} (A : Vector (DeterminantAlgorithm.Table d) (n + 1)) : pointWordOfTables (A.toList.map fun T => rowsOf (DeterminantAlgorithm.denote T)) = let den := DeterminantAlgorithm.determinant (A.get 0) if den = 0 then [] @@ -177,7 +177,8 @@ theorem pointWordOfTables_eq {n d : ℕ} (A : Vector (DeterminantAlgorithm.Table /-- `pointWordsOfTables` on the row lists of `A` produces `[]` when singular and the singleton encoded tuple when nonsingular. -/ -theorem pointWordsOfTables_eq {n d : ℕ} (A : Vector (DeterminantAlgorithm.Table d) (n + 1)) : +private theorem pointWordsOfTables_eq {n d : ℕ} + (A : Vector (DeterminantAlgorithm.Table d) (n + 1)) : pointWordsOfTables (A.toList.map fun T => rowsOf (DeterminantAlgorithm.denote T)) = let den := DeterminantAlgorithm.determinant (A.get 0) if den = 0 then [] diff --git a/Complexity/Computability/Circuit/Rational/SmallExpansion.lean b/Complexity/Computability/Circuit/Rational/SmallExpansion.lean index 92f271973..298f38be8 100644 --- a/Complexity/Computability/Circuit/Rational/SmallExpansion.lean +++ b/Complexity/Computability/Circuit/Rational/SmallExpansion.lean @@ -78,11 +78,11 @@ lemma polynomialMap_coeff_high (M : ℕ) (x : Fin M → K) (j : ℕ) (hj : M ≤ def polynomialSpace {M : ℕ} (V : Submodule K (Fin M → K)) : Submodule K K[X] := V.map (polynomialMap M) -lemma finrank_polynomialSpace {M : ℕ} (V : Submodule K (Fin M → K)) : +private lemma finrank_polynomialSpace {M : ℕ} (V : Submodule K (Fin M → K)) : finrank K (polynomialSpace V) = finrank K V := finrank_map_injective _ (polynomialMap_injective M) V -lemma polynomialSpace_bound {M : ℕ} (V : Submodule K (Fin M → K)) : +private lemma polynomialSpace_bound {M : ℕ} (V : Submodule K (Fin M → K)) : ∀ f ∈ polynomialSpace V, f ≠ 0 → f.natDegree < M := by rintro f ⟨x, hx, rfl⟩ hn exact (natDegree_lt_iff_degree_lt hn).mpr (Polynomial.mem_degreeLT.mp (polynomialMap_mem M x)) @@ -112,7 +112,7 @@ lemma testMap_injective (M : ℕ) (a : K) : Function.Injective (testMap M a) := conjugatedWeight_injective _ _ _ /-- Kernel of the low Taylor projection is precisely the vanishing filtration. -/ -lemma map_taylor_projection_kernel (M : ℕ) (a : K) (A : ℕ) +private lemma map_taylor_projection_kernel (M : ℕ) (a : K) (A : ℕ) (V : Submodule K (Fin M → K)) : (V ⊓ ((lowProjection Fin.val A).comp (taylorCoordinates M a).toLinearMap).ker).map (polynomialMap M) = vanishingFiltration (polynomialSpace V) a (A + 1) := by @@ -135,7 +135,7 @@ lemma map_taylor_projection_kernel (M : ℕ) (a : K) (A : ℕ) exact hx j.val.val (by have := j.property; omega) /-- The output-side low reverse coordinates mean high ordinary Taylor order. -/ -lemma map_reverseTaylor_lowSupported (M : ℕ) (a : K) (A : ℕ) +private lemma map_reverseTaylor_lowSupported (M : ℕ) (a : K) (A : ℕ) (V : Submodule K (Fin M → K)) : ((V.map (reverseTaylorCoordinates M a).toLinearMap) ⊓ lowSupported Fin.val A).map ((polynomialMap M).comp (reverseTaylorCoordinates M a).symm.toLinearMap) = @@ -157,7 +157,7 @@ lemma map_reverseTaylor_lowSupported (M : ℕ) (a : K) (A : ℕ) exact hx j.rev.val (by simp only [Fin.val_rev]; omega) · simp -lemma finrank_lowTaylor (M : ℕ) (a : K) (A : ℕ) +private lemma finrank_lowTaylor (M : ℕ) (a : K) (A : ℕ) (V : Submodule K (Fin M → K)) {h : ℕ} (b : Basis (Fin h) K (polynomialSpace V)) (hb : Function.Injective (fun j => (b j : K[X]).rootMultiplicity a)) : @@ -180,7 +180,7 @@ lemma finrank_lowTaylor (M : ℕ) (a : K) (A : ℕ) (fun j : Fin h => (b j : K[X]).rootMultiplicity a ≤ A) omega -lemma finrank_reverseTaylor (M : ℕ) (a : K) (A : ℕ) +private lemma finrank_reverseTaylor (M : ℕ) (a : K) (A : ℕ) (V : Submodule K (Fin M → K)) {h : ℕ} (b : Basis (Fin h) K (polynomialSpace V)) (hb : Function.Injective (fun j => (b j : K[X]).rootMultiplicity a)) : @@ -192,7 +192,7 @@ lemma finrank_reverseTaylor (M : ℕ) (a : K) (A : ℕ) map_reverseTaylor_lowSupported, finrank_vanishingFiltration b a hb] /-- The rank form of order reversal, at every threshold. -/ -theorem order_reversal_counts (M : ℕ) (a : K) (A : ℕ) +private theorem order_reversal_counts (M : ℕ) (a : K) (A : ℕ) (U W : Submodule (F K) (Fin M → F K)) (hW : U.map (testMap M a) ≤ W) {k l : ℕ} (b : Basis (Fin k) K (polynomialSpace (reducedSubspace U))) (c : Basis (Fin l) K (polynomialSpace (reducedSubspace W))) @@ -205,7 +205,7 @@ theorem order_reversal_counts (M : ℕ) (a : K) (A : ℕ) rwa [finrank_lowTaylor M a A _ b hb, finrank_reverseTaylor M a A _ c hc] at hh /-- Counting all thresholds counts each order with its exact multiplicity. -/ -lemma sum_threshold_counts {h : ℕ} (d : Fin h → ℕ) (L : ℕ) : +private lemma sum_threshold_counts {h : ℕ} (d : Fin h → ℕ) (L : ℕ) : (∑ A ∈ Finset.range L, Fintype.card {j : Fin h // d j ≤ A}) = ∑ j, (L - d j) := by classical @@ -220,7 +220,7 @@ lemma sum_threshold_counts {h : ℕ} (d : Fin h → ℕ) (L : ℕ) : tauto rw [← Finset.card_filter, he, Nat.card_Ico] -lemma sum_reversed_counts {h : ℕ} (d : Fin h → ℕ) (L : ℕ) (hd : ∀ j, d j ≤ L) : +private lemma sum_reversed_counts {h : ℕ} (d : Fin h → ℕ) (L : ℕ) (hd : ∀ j, d j ≤ L) : (∑ A ∈ Finset.range L, Fintype.card {j : Fin h // L - A ≤ d j}) = ∑ j, d j := by have he : ∀ A, (fun j : Fin h => L - A ≤ d j) = (fun j : Fin h => L - d j ≤ A) := by intro A @@ -272,12 +272,12 @@ theorem order_reversal_sum (M : ℕ) (a : K) Fintype.card_fin, smul_eq_mul] omega -lemma sum_fin_val_le_square (h : ℕ) : (∑ j : Fin h, j.val) ≤ h * h := by +private lemma sum_fin_val_le_square (h : ℕ) : (∑ j : Fin h, j.val) ≤ h * h := by calc _ ≤ ∑ _j : Fin h, h := Finset.sum_le_sum fun j _ => Nat.le_of_lt j.isLt _ = h * h := by simp -lemma expansion_numeric (w B M N k l : ℕ) (hw : 1 ≤ w) (hN : 1 ≤ N) +private lemma expansion_numeric (w B M N k l : ℕ) (hw : 1 ≤ w) (hN : 1 ≤ N) (hMN : M = N + 2 * w ^ 3 * B) (hk : 1 ≤ k) (hkB : k ≤ B) (hh : w * (k * (M - 1)) ≤ k * (N - 1) + w * (∑ j : Fin k, j.val) + (l * (M - 1) + w * (∑ j : Fin l, j.val))) : @@ -321,7 +321,7 @@ lemma expansion_numeric (w B M N k l : ℕ) (hw : 1 ≤ w) (hN : 1 ≤ N) nlinarith only [hbase] nlinarith -lemma reduced_degree_bound {M N : ℕ} (U : Submodule (F K) (Fin M → F K)) +private lemma reduced_degree_bound {M N : ℕ} (U : Submodule (F K) (Fin M → F K)) (hU : ∀ x ∈ U, ∀ j : Fin M, N ≤ j.val → x j = 0) : ∀ f ∈ polynomialSpace (reducedSubspace U), f ≠ 0 → f.natDegree < N := by have hr : ∀ y ∈ reducedSubspace U, ∀ j : Fin M, N ≤ j.val → y j = 0 := by diff --git a/Complexity/Computability/Circuit/Rational/Wronskian.lean b/Complexity/Computability/Circuit/Rational/Wronskian.lean index c6eef5a1c..87cfebbd2 100644 --- a/Complexity/Computability/Circuit/Rational/Wronskian.lean +++ b/Complexity/Computability/Circuit/Rational/Wronskian.lean @@ -67,7 +67,7 @@ def wronskianFamily {K : Type*} [CommRing K] {h : ℕ} (f : Fin h → K[X]) : K[ /-- Factoring prescribed powers from the columns keeps track of the first possible coefficient of a determinant. -/ -lemma det_factor_column_orders {K ι : Type*} [CommRing K] +private lemma det_factor_column_orders {K ι : Type*} [CommRing K] [Fintype ι] [DecidableEq ι] (A : Matrix ι ι K[X]) (d : ι → ℕ) (hd : ∀ i j, X ^ d j ∣ A i j) : ∃ B : Matrix ι ι K[X], @@ -86,7 +86,7 @@ lemma det_factor_column_orders {K ι : Type*} [CommRing K] rw [hB i j, coeff_X_pow_mul'] simp -lemma coeff_scaled_derivative_at {K : Type*} [CommRing K] +private lemma coeff_scaled_derivative_at {K : Type*} [CommRing K] (f : K[X]) (r d : ℕ) : (X ^ r * derivative^[r] f).coeff d = (d.descFactorial r : K) * f.coeff d := by @@ -96,7 +96,7 @@ lemma coeff_scaled_derivative_at {K : Type*} [CommRing K] · rw [coeff_X_pow_mul', ite_eq_right hr, Nat.descFactorial_eq_zero_iff_lt.mpr (Nat.lt_of_not_ge hr), Nat.cast_zero, zero_mul] -lemma scaled_derivative_order {K : Type*} [CommRing K] +private lemma scaled_derivative_order {K : Type*} [CommRing K] (f : K[X]) (r : ℕ) : X ^ f.natTrailingDegree ∣ X ^ r * derivative^[r] f := by apply X_pow_dvd_iff.mpr intro a ha @@ -172,7 +172,7 @@ lemma wronskian_order_of_distinct_orders {K : Type*} [Field K] [CharZero K] /-- Polynomial row reduction, derived rather than assumed: every bounded-degree subspace has a basis with distinct largest degrees. -/ -lemma exists_degree_echelon_family {K : Type*} [Field K] +private lemma exists_degree_echelon_family {K : Type*} [Field K] (d : ℕ) (V : Submodule K K[X]) (hV : ∀ f ∈ V, f ≠ 0 → f.natDegree < d) : ∃ (h : ℕ) (f : Fin h → K[X]), LinearIndependent K f ∧ @@ -263,7 +263,7 @@ lemma exists_degree_echelon_family {K : Type*} [Field K] /-- Fixed-length coefficient reversal is linear, unlike degree-dependent polynomial reversal. -/ -def reflectLinearEquiv (K : Type*) [Field K] (N : ℕ) : K[X] ≃ₗ[K] K[X] where +private def reflectLinearEquiv (K : Type*) [Field K] (N : ℕ) : K[X] ≃ₗ[K] K[X] where toFun := reflect N invFun := reflect N left_inv := fun _ => reflect_reflect @@ -273,7 +273,7 @@ def reflectLinearEquiv (K : Type*) [Field K] (N : ℕ) : K[X] ≃ₗ[K] K[X] whe intro c f simpa only [smul_eq_C_mul, RingHom.id_apply] using reflect_C_mul f c N -lemma order_reflect {K : Type*} [Field K] (N : ℕ) (f : K[X]) +private lemma order_reflect {K : Type*} [Field K] (N : ℕ) (f : K[X]) (hf : f ≠ 0) (hd : f.natDegree ≤ N) : (reflect N f).natTrailingDegree = N - f.natDegree := by apply le_antisymm @@ -285,7 +285,7 @@ lemma order_reflect {K : Type*} [Field K] (N : ℕ) (f : K[X]) rw [coeff_reflect, revAt_le (by omega)] exact coeff_eq_zero_of_natDegree_lt (by omega) -lemma exists_order_echelon_family {K : Type*} [Field K] +private lemma exists_order_echelon_family {K : Type*} [Field K] (d : ℕ) (V : Submodule K K[X]) (hV : ∀ f ∈ V, f ≠ 0 → f.natDegree < d) : ∃ (h : ℕ) (f : Fin h → K[X]), LinearIndependent K f ∧ @@ -326,7 +326,7 @@ lemma exists_order_echelon_family {K : Type*} [Field K] change (g i).natDegree = (g j).natDegree omega -lemma wronskian_linearCombination {K : Type*} [CommRing K] {h : ℕ} +private lemma wronskian_linearCombination {K : Type*} [CommRing K] {h : ℕ} (f : Fin h → K[X]) (A : Matrix (Fin h) (Fin h) K) : wronskianFamily (fun j => ∑ i, A i j • f i) = wronskianFamily f * C A.det := by have he : (Matrix.of fun r j : Fin h => @@ -347,14 +347,14 @@ lemma wronskian_linearCombination {K : Type*} [CommRing K] {h : ℕ} congr 1 exact (C.map_det A).symm -lemma basis_toMatrix_det_ne_zero {K M : Type*} [Field K] [AddCommGroup M] +private lemma basis_toMatrix_det_ne_zero {K M : Type*} [Field K] [AddCommGroup M] [Module K M] {h : ℕ} (b b' : Basis (Fin h) K M) : (b.toMatrix b').det ≠ 0 := by have hh := congrArg Matrix.det (b.toMatrix_mul_toMatrix_flip b') rw [Matrix.det_mul, Matrix.det_one] at hh exact left_ne_zero_of_mul_eq_one hh -lemma wronskian_basis_change {K : Type*} [Field K] {h : ℕ} +private lemma wronskian_basis_change {K : Type*} [Field K] {h : ℕ} {V : Submodule K K[X]} (b b' : Basis (Fin h) K V) : wronskianFamily (fun j => (b' j : K[X])) = wronskianFamily (fun j => (b j : K[X])) * C (b.toMatrix b').det := by @@ -365,7 +365,7 @@ lemma wronskian_basis_change {K : Type*} [Field K] {h : ℕ} simpa only [Submodule.coe_sum, Submodule.coe_smul, Basis.toMatrix_apply] using hh.symm rw [he, wronskian_linearCombination] -lemma exists_order_echelon_basis {K : Type*} [Field K] +private lemma exists_order_echelon_basis {K : Type*} [Field K] (d : ℕ) (V : Submodule K K[X]) {h : ℕ} (b : Basis (Fin h) K V) (hV : ∀ f ∈ V, f ≠ 0 → f.natDegree < d) : ∃ b' : Basis (Fin h) K V, @@ -383,7 +383,7 @@ lemma exists_order_echelon_basis {K : Type*} [Field K] subst k exact ⟨b', by simpa only [hb'] using hord⟩ -lemma wronskian_basis_ne_zero {K : Type*} [Field K] [CharZero K] +private lemma wronskian_basis_ne_zero {K : Type*} [Field K] [CharZero K] (d : ℕ) {V : Submodule K K[X]} {h : ℕ} (b : Basis (Fin h) K V) (hV : ∀ f ∈ V, f ≠ 0 → f.natDegree < d) : wronskianFamily (fun j => (b j : K[X])) ≠ 0 := by @@ -395,12 +395,12 @@ lemma wronskian_basis_ne_zero {K : Type*} [Field K] [CharZero K] rw [wronskian_basis_change b b'] at hn exact (mul_ne_zero_iff.mp hn).1 -lemma derivative_taylor {K : Type*} [CommRing K] (a : K) (f : K[X]) : +private lemma derivative_taylor {K : Type*} [CommRing K] (a : K) (f : K[X]) : derivative (taylor a f) = taylor a (derivative f) := by simp only [taylor_apply, derivative_comp, derivative_add, derivative_X, derivative_C, add_zero, one_mul] -lemma iterate_derivative_taylor {K : Type*} [CommRing K] (a : K) +private lemma iterate_derivative_taylor {K : Type*} [CommRing K] (a : K) (f : K[X]) (r : ℕ) : derivative^[r] (taylor a f) = taylor a (derivative^[r] f) := by induction r with @@ -408,7 +408,7 @@ lemma iterate_derivative_taylor {K : Type*} [CommRing K] (a : K) | succ r ih => rw [Function.iterate_succ_apply', ih, derivative_taylor, Function.iterate_succ_apply'] -lemma wronskian_taylor {K : Type*} [CommRing K] {h : ℕ} +private lemma wronskian_taylor {K : Type*} [CommRing K] {h : ℕ} (a : K) (f : Fin h → K[X]) : wronskianFamily (fun j => taylor a (f j)) = taylor a (wronskianFamily f) := by unfold wronskianFamily @@ -420,7 +420,7 @@ lemma wronskian_taylor {K : Type*} [CommRing K] {h : ℕ} rw [he] exact ((taylorEquiv a).toRingHom.map_det _).symm -lemma natDegree_wronskian_le {K : Type*} [CommRing K] {h : ℕ} +private lemma natDegree_wronskian_le {K : Type*} [CommRing K] {h : ℕ} (f : Fin h → K[X]) (D : ℕ) (hd : ∀ j, (f j).natDegree ≤ D) : (wronskianFamily f).natDegree ≤ h * D := by unfold wronskianFamily @@ -435,7 +435,7 @@ lemma natDegree_wronskian_le {K : Type*} [CommRing K] {h : ℕ} (natDegree_iterate_derivative _ _).trans ((Nat.sub_le _ _).trans (hd j)) _ = h * D := by simp -lemma sum_rootMultiplicity_le_natDegree {K : Type*} [Field K] +private lemma sum_rootMultiplicity_le_natDegree {K : Type*} [Field K] (f : K[X]) (s : Finset K) : ∑ a ∈ s, f.rootMultiplicity a ≤ f.natDegree := by classical @@ -447,7 +447,7 @@ lemma sum_rootMultiplicity_le_natDegree {K : Type*} [Field K] Finset.mem_union_right _ (Multiset.mem_toFinset.mpr ha)) _ ≤ f.natDegree := card_roots' f -lemma wronskian_order_at {K : Type*} [Field K] [CharZero K] {h : ℕ} +private lemma wronskian_order_at {K : Type*} [Field K] [CharZero K] {h : ℕ} (a : K) (f : Fin h → K[X]) (hf : ∀ j, f j ≠ 0) (hd : Function.Injective (fun j => (f j).rootMultiplicity a)) : (wronskianFamily f).rootMultiplicity a + (∑ i : Fin h, i.val) = @@ -461,7 +461,7 @@ lemma wronskian_order_at {K : Type*} [Field K] [CharZero K] {h : ℕ} rw [wronskian_taylor] at hh simpa only [rootMultiplicity_eq_natTrailingDegree, ← taylor_apply] using hh -lemma wronskian_basis_rootMultiplicity {K : Type*} [Field K] [CharZero K] +private lemma wronskian_basis_rootMultiplicity {K : Type*} [Field K] [CharZero K] (d : ℕ) {V : Submodule K K[X]} {h : ℕ} (b b' : Basis (Fin h) K V) (a : K) (hV : ∀ f ∈ V, f ≠ 0 → f.natDegree < d) : @@ -531,7 +531,7 @@ lemma exists_echelon_basis_at {K : Type*} [Field K] /-- Distinct leading orders make vanishing conditions triangular; no linear combination can cancel its first nonzero echelon term. -/ -lemma low_coefficients_force_zero {K : Type*} [Field K] {h : ℕ} +private lemma low_coefficients_force_zero {K : Type*} [Field K] {h : ℕ} (f : Fin h → K[X]) (hf : ∀ j, f j ≠ 0) (hd : Function.Injective (fun j => (f j).natTrailingDegree)) (c : Fin h → K) (r : ℕ) @@ -587,7 +587,7 @@ lemma mem_vanishingFiltration_iff_dvd {K : Type*} [Field K] rw [X_sub_C_pow_dvd_iff, X_pow_dvd_iff] rfl -lemma vanishingFiltration_eq_span {K : Type*} [Field K] +private lemma vanishingFiltration_eq_span {K : Type*} [Field K] {V : Submodule K K[X]} {h : ℕ} (b : Basis (Fin h) K V) (a : K) (hb : Function.Injective (fun j => (b j : K[X]).rootMultiplicity a)) (r : ℕ) : diff --git a/Complexity/Computability/Circuit/SimulationContext.lean b/Complexity/Computability/Circuit/SimulationContext.lean index 4816d87b0..18919e695 100644 --- a/Complexity/Computability/Circuit/SimulationContext.lean +++ b/Complexity/Computability/Circuit/SimulationContext.lean @@ -62,7 +62,7 @@ def Circuit.withContext (c : Circuit σ n m) (q : ℕ) : Circuit (σ.withContext (c.comp (wiring σ (Fin.natAdd q))).mapLines (Line.withContext q) /-- Adding context does not add gates or change their costs. -/ -theorem Circuit.cost_program_withContext (c : Circuit σ n m) (q : ℕ) (cost : σ.Op → ℕ) : +private theorem Circuit.cost_program_withContext (c : Circuit σ n m) (q : ℕ) (cost : σ.Op → ℕ) : (c.withContext q).program.cost cost = c.program.cost cost := by change ((c.comp (wiring σ (Fin.natAdd q))).program.mapLines (Line.withContext q)).cost cost = _