Documentation

DescriptiveComplexity.Problems.Knapsack.Chain

Adding up binary weights along the item order #

The certificate of a binary-weighted problem walks the items in order and carries the running total: PS i is the total over the chosen items up to i, and Cy i the carries of the step that appends i. The conditions the walk must satisfy – every bit the exclusive or of the three inputs, every carry their majority, no carry into the lowest position, none out of the highest – are DescriptiveComplexity.IsChain, and this file proves the two statements the Σ₁ definitions need:

Nothing here mentions a vocabulary: the items, their order and the bit positions are all parameters, because the clients need different ones.

Partial sums along the item order #

noncomputable def DescriptiveComplexity.PartSum {A : Type} (Le : AAProp) (S : AProp) (w : A) (i : A) :

The running total of the weights w over the chosen items up to i.

Equations
Instances For
    Dependency graph
    theorem DescriptiveComplexity.partSum_min {A : Type} {ILe : AAProp} {IItem S : AProp} {w : A} (hlin : IsLinOrd ILe) (hS : ∀ (i : A), S iIItem i) {i : A} (hi : MinPos ILe IItem i) :
    PartSum ILe S w i = if S i then w i else 0

    At the first item, the running total is that item's contribution.

    Dependency graph
    theorem DescriptiveComplexity.partSum_succ {A : Type} [Finite A] {ILe : AAProp} {IItem S : AProp} {w : A} (hlin : IsLinOrd ILe) (hS : ∀ (i : A), S iIItem i) {h i : A} (hsucc : SuccPos ILe IItem h i) :
    PartSum ILe S w i = PartSum ILe S w h + if S i then w i else 0

    Each step of the walk adds one item's contribution.

    Dependency graph
    theorem DescriptiveComplexity.partSum_le {A : Type} [Finite A] {ILe : AAProp} {S : AProp} {w : A} (i : A) :
    PartSum ILe S w i ∑ᶠ (j : A) (_ : j {j : A | S j}), w j

    A running total never exceeds the total.

    Dependency graph
    theorem DescriptiveComplexity.partSum_max {A : Type} {ILe : AAProp} {IItem S : AProp} {w : A} (hS : ∀ (i : A), S iIItem i) {i : A} (hi : MaxPos ILe IItem i) :
    PartSum ILe S w i = ∑ᶠ (j : A) (_ : j {j : A | S j}), w j

    At the last item, the running total is the total.

    Dependency graph
    theorem DescriptiveComplexity.xor3_iff (x y z : Prop) :
    Xor x (Xor y z) (x (y z))

    The parity of three bits, as an iterated equivalence.

    Dependency graph

    Walks along the item order #

    def DescriptiveComplexity.ChainAdd {A P : Type} (S : AProp) (wt : APProp) (i : A) (p : P) :

    The bit that an item contributes at a position: its own bit, if chosen.

    Equations
    Instances For
      Dependency graph
      theorem DescriptiveComplexity.binNum_chainAdd {A P : Type} (PLe : PPProp) (PPosn : PProp) (S : AProp) (wt : APProp) (i : A) :
      binNum PLe PPosn (ChainAdd S wt i) = if S i then binNum PLe PPosn (wt i) else 0

      An item contributes its weight, or nothing.

      Dependency graph
      def DescriptiveComplexity.IsChain {A P : Type} (Le : AAProp) (Item : AProp) (PLe : PPProp) (PPosn : PProp) (S : AProp) (wt PS Cy : APProp) :

      A ripple-carry walk along the items: PS i is the running total up to i and Cy i the carries of the step appending i.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        Dependency graph
        theorem DescriptiveComplexity.chain_sound {A : Type} [Finite A] {ILe : AAProp} {IItem : AProp} {P : Type} [Finite P] {PLe : PPProp} {PPosn : PProp} {S : AProp} {wt PS Cy : APProp} (hlin : IsLinOrd ILe) (hPlin : IsLinOrd PLe) (hS : ∀ (i : A), S iIItem i) (hchain : IsChain ILe IItem PLe PPosn S wt PS Cy) (i : A) :
        IItem ibinNum PLe PPosn (PS i) = PartSum ILe S (fun (j : A) => binNum PLe PPosn (wt j)) i

        A walk computes the running totals.

        Dependency graph
        theorem DescriptiveComplexity.exists_chain {A : Type} [Finite A] {ILe : AAProp} {IItem : AProp} {P : Type} [Finite P] {PLe : PPProp} {PPosn : PProp} {S : AProp} {wt : APProp} (hlin : IsLinOrd ILe) (hPlin : IsLinOrd PLe) (hS : ∀ (i : A), S iIItem i) (hbound : ∑ᶠ (j : A) (_ : j {j : A | S j}), binNum PLe PPosn (wt j) < 2 ^ {p : P | PPosn p}.ncard) :
        ∃ (PS : APProp) (Cy : APProp), IsChain ILe IItem PLe PPosn S wt PS Cy

        A walk exists whenever the total fits in the positions: this is the certificate a yes-instance offers.

        Dependency graph