Documentation

CslibFrontier.Computability.Circuit.SlpCost

Costs of straight-line programs over all operations on a finite set #

Cslib.Circuits.SlpN inp p H: the functions of H are computed by a straight-line program with p gates over all operations on Fin D (fullSignature 2 (Fin D)), from the inputs inp. Gates are added one at a time (Cslib.Circuits.SlpN.snoc), the inputs take one gate each (Cslib.Circuits.SlpN.inputs), and a program runs unchanged over a larger alphabet (Cslib.Circuits.SlpN.castLE).

Cslib.Circuits.Cost D A c h is the calculus on top: h is computed in c further gates from the functions of A, by constants and binary operations whose values stay below D. It is turned into gates by Cslib.Circuits.Cost.run and, for a family, by Cslib.Circuits.SlpN.stage. Cslib.Circuits.CostP is the same for properties, through their indicators, with rules for relations, connectives, bounded quantifiers and choice (Cslib.Circuits.Cost.ite).

Main definitions #

Main results #

References #

def Cslib.Circuits.SlpN {Inp : Type} {D n : ℕ} (inp : Fin n → Inp → Fin D) (p : ℕ) (H : Set (Inp → ℕ)) :

The functions of H (with values in ℕ) are computed by a straight-line program with p gates over all operations on Fin D, from the inputs inp.

theorem Cslib.Circuits.SlpN.mono {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} {p : ℕ} {H H' : Set (Inp → ℕ)} (h : SlpN inp p H) (hs : H' ⊆ H) :
SlpN inp p H'
theorem Cslib.Circuits.SlpN.empty {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} :
SlpN inp 0 ∅
theorem Cslib.Circuits.SlpN.snoc {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} {p : ℕ} {H : Set (Inp → ℕ)} (h : SlpN inp p H) (f : Inp → Fin D) (hf : (∃ (i : Fin n), f = inp i) ∨ (∃ (c : Fin D), f = fun (x : Inp) => c) ∨ ∃ h1 ∈ H, ∃ h2 ∈ H, ∃ (φ : Fin D → Fin D → Fin D), ∀ (x : Inp) (a b : Fin D), ↑a = h1 x → ↑b = h2 x → f x = φ a b) :
SlpN inp (p + 1) (insert (fun (x : Inp) => ↑(f x)) H)

One gate more: an input, a constant, or a binary operation of two computed functions.

theorem Cslib.Circuits.SlpN.le {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} (hD : 0 < D) {p q : ℕ} (hpq : p ≤ q) {H : Set (Inp → ℕ)} (h : SlpN inp p H) :
SlpN inp q H

More gates do not hurt.

theorem Cslib.Circuits.SlpN.castLE {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} {D' : ℕ} (hD : D ≤ D') {inp' : Fin n → Inp → Fin D'} (hinp : ∀ (i : Fin n) (x : Inp), ↑(inp' i x) = ↑(inp i x)) {p : ℕ} {H : Set (Inp → ℕ)} (h : SlpN inp p H) :
SlpN inp' p H

A larger alphabet: the gates of a program over Fin D compute the same numbers over Fin D', for D ≤ D', from inputs with the same values.

theorem Cslib.Circuits.SlpN.mapInputs {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} {n' : ℕ} {inp' : Fin n' → Inp → Fin D} (f : Fin n → Fin n') (hf : ∀ (i : Fin n) (x : Inp), inp' (f i) x = inp i x) {p : ℕ} {H : Set (Inp → ℕ)} (h : SlpN inp p H) :
SlpN inp' p H

A program whose inputs are among the inputs inp' computes the same functions from them.

theorem Cslib.Circuits.SlpN.inputs {Inp : Type} {D n : ℕ} (inp : Fin n → Inp → Fin D) :
SlpN inp n (Set.range fun (i : Fin n) (x : Inp) => ↑(inp i x))

The inputs take one gate each.

theorem Cslib.Circuits.SlpN.exists_isSlpStep {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} [NeZero D] {p : ℕ} {H : Set (Inp → ℕ)} (h : SlpN inp p H) :
∃ (fn : ℕ → Inp → Fin D), (∀ k < n + p, IsSlpStep inp fn k) ∧ ∀ f ∈ H, ∃ (k : Fin (n + p)), ∀ (x : Inp), ↑(fn (↑k) x) = f x

A program with p gates on n inputs gives a list of n + p steps, inputs first, in which every function that the program computes is a step.

inductive Cslib.Circuits.Cost {Inp : Type} (D : ℕ) (A : Set (Inp → ℕ)) :
ℕ → (Inp → ℕ) → Prop

h is computed in at most c steps from functions of A.

  • base {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {h : Inp → ℕ} : h ∈ A → Cost D A 0 h

    available

  • const {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (c : ℕ) : c < D → Cost D A 1 fun (x : Inp) => c

    constants

  • op {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {p q : ℕ} {h1 h2 : Inp → ℕ} (φ : ℕ → ℕ → ℕ) : Cost D A p h1 → Cost D A q h2 → (∀ (x : Inp), φ (h1 x) (h2 x) < D) → Cost D A (p + q + 1) fun (x : Inp) => φ (h1 x) (h2 x)

    binary operations

  • mono {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {p q : ℕ} {h : Inp → ℕ} : Cost D A p h → p ≤ q → Cost D A q h

    idle steps

theorem Cslib.Circuits.Cost.run {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} {A : Set (Inp → ℕ)} (hD : 0 < D) {c : ℕ} {h : Inp → ℕ} (hc : Cost D A c h) {p : ℕ} {H : Set (Inp → ℕ)} :
A ⊆ H → SlpN inp p H → SlpN inp (p + c) (insert h H)

Running a computation.

theorem Cslib.Circuits.SlpN.stage {Inp : Type} {D n : ℕ} {inp : Fin n → Inp → Fin D} (hD : 0 < D) {κ : Type u_1} [Fintype κ] {p : ℕ} {H : Set (Inp → ℕ)} (h : SlpN inp p H) (f : κ → Inp → ℕ) (c : ℕ) (hf : ∀ (i : κ), Cost D H c (f i)) :
SlpN inp (p + Fintype.card κ * c) (H ∪ Set.range f)

A family of functions.

theorem Cslib.Circuits.Cost.congr {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {c : ℕ} {h h' : Inp → ℕ} (hc : Cost D A c h) (e : ∀ (x : Inp), h x = h' x) :
Cost D A c h'
theorem Cslib.Circuits.Cost.weaken {Inp : Type} {D : ℕ} {A A' : Set (Inp → ℕ)} (hA : A ⊆ A') {c : ℕ} {h : Inp → ℕ} (hc : Cost D A c h) :
Cost D A' c h
theorem Cslib.Circuits.Cost.op1 {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 0 < D) {p : ℕ} {h : Inp → ℕ} (φ : ℕ → ℕ) (hc : Cost D A p h) (hφ : ∀ (x : Inp), φ (h x) < D) :
Cost D A (p + 2) fun (x : Inp) => φ (h x)

A unary operation.

theorem Cslib.Circuits.Cost.sum {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 0 < D) {κ : Type u_1} (s : Finset κ) {c : ℕ} {h : κ → Inp → ℕ} (hc : ∀ i ∈ s, Cost D A c (h i)) (hb : ∀ (x : Inp), ∑ i ∈ s, h i x < D) :
Cost D A (s.card * (c + 1) + 1) fun (x : Inp) => ∑ i ∈ s, h i x

Sums.

def Cslib.Circuits.CostP {Inp : Type} (D : ℕ) (A : Set (Inp → ℕ)) (c : ℕ) (P : Inp → Prop) :

A property is decided in at most c steps.

theorem Cslib.Circuits.costP_iff {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {c : ℕ} {P : Inp → Prop} :
CostP D A c P ↔ Cost D A c ({x : Inp | P x}.indicator 1)

A property is decided in c steps when its indicator is computed in c steps.

theorem Cslib.Circuits.CostP.congr {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {c : ℕ} {P Q : Inp → Prop} (hc : CostP D A c P) (h : ∀ (x : Inp), P x ↔ Q x) :
CostP D A c Q
theorem Cslib.Circuits.CostP.mono {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {p q : ℕ} {P : Inp → Prop} (hc : CostP D A p P) (h : p ≤ q) :
CostP D A q P
theorem Cslib.Circuits.CostP.rel {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {p q : ℕ} {h1 h2 : Inp → ℕ} (r : ℕ → ℕ → Prop) (c1 : Cost D A p h1) (c2 : Cost D A q h2) :
CostP D A (p + q + 1) fun (x : Inp) => r (h1 x) (h2 x)

A relation between two values.

theorem Cslib.Circuits.CostP.rel1 {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {p : ℕ} {h : Inp → ℕ} (r : ℕ → Prop) (c1 : Cost D A p h) :
CostP D A (p + 2) fun (x : Inp) => r (h x)

A property of a value.

theorem Cslib.Circuits.CostP.true' {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) :
CostP D A 1 fun (x : Inp) => True
theorem Cslib.Circuits.CostP.false' {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) :
CostP D A 1 fun (x : Inp) => False
theorem Cslib.Circuits.CostP.const {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) (P : Prop) :
CostP D A 1 fun (x : Inp) => P

A constant property.

theorem Cslib.Circuits.CostP.and {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {p q : ℕ} {P Q : Inp → Prop} (c1 : CostP D A p P) (c2 : CostP D A q Q) :
CostP D A (p + q + 1) fun (x : Inp) => P x ∧ Q x
theorem Cslib.Circuits.CostP.or {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {p q : ℕ} {P Q : Inp → Prop} (c1 : CostP D A p P) (c2 : CostP D A q Q) :
CostP D A (p + q + 1) fun (x : Inp) => P x ∨ Q x
theorem Cslib.Circuits.CostP.not {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {p : ℕ} {P : Inp → Prop} (c1 : CostP D A p P) :
CostP D A (p + 2) fun (x : Inp) => ¬P x
theorem Cslib.Circuits.CostP.exists_mem {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {κ : Type u_1} (s : Finset κ) {c : ℕ} {P : κ → Inp → Prop} (hc : ∀ i ∈ s, CostP D A c (P i)) :
CostP D A (s.card * (c + 1) + 1) fun (x : Inp) => ∃ i ∈ s, P i x
theorem Cslib.Circuits.CostP.forall_mem {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} (hD : 1 < D) {κ : Type u_1} (s : Finset κ) {c : ℕ} {P : κ → Inp → Prop} (hc : ∀ i ∈ s, CostP D A c (P i)) :
CostP D A (s.card * (c + 1) + 1) fun (x : Inp) => ∀ i ∈ s, P i x
theorem Cslib.Circuits.Cost.ite {Inp : Type} {D : ℕ} {A : Set (Inp → ℕ)} {c p q : ℕ} {P : Inp → Prop} [DecidablePred P] {h1 h2 : Inp → ℕ} (c0 : CostP D A c P) (c1 : Cost D A p h1) (c2 : Cost D A q h2) (b1 : ∀ (x : Inp), h1 x < D) (b2 : ∀ (x : Inp), h2 x < D) :
Cost D A (2 * c + p + q + 3) fun (x : Inp) => if P x then h1 x else h2 x

A choice.