While this submission is a draft, it cannot be used by other submissions.

Counting knapsack and 0-1 integer programming solutions

Lax280166.CountingKnapsacks · concepts/Lax280166/CountingKnapsacks.lean · lax-280166

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    The weights are written in binary as in the NP catalog. #Knapsack counts the sets of items whose total weight is exactly the target, and #0-1 Integer Programming counts the 00-11 vectors satisfying every constraint of the system with equality.

    Concept map
    13 concepts; 25 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Tactic.FinCases
    2import Mathlib.Order.PiLex
    3import Mathlib.Data.Prod.Lex
    4import Mathlib.Data.Fintype.EquivFin
    5import Mathlib.ModelTheory.Order
    6import Mathlib.ModelTheory.Semantics
    7import Mathlib.ModelTheory.Complexity
    8import Mathlib.Logic.Equiv.Fin.Basic
    9import Mathlib.Data.Fintype.Lattice
    10import Mathlib.Data.Finite.Sigma
    11import Mathlib.Order.Lattice.Nat
    12import Mathlib.Data.Set.Card
    13import Mathlib.Data.Fintype.Pigeonhole
    14import Mathlib.Dynamics.FixedPoints.Basic
    15import Mathlib.ModelTheory.Syntax
    16import Mathlib.Algebra.Order.BigOperators.Group.Finset
    17import Mathlib.Data.Fintype.Card
    18import Mathlib.SetTheory.Cardinal.Finite
    19import Mathlib.Algebra.BigOperators.Finprod
    20import Mathlib.Data.Set.Finite.Lemmas
    21import Mathlib.Logic.Equiv.Prod
    22import Lax799700.Knapsack
    23import Lax799700.ZeroOneIP
    24import Lax904597.Machines
    25import Mathlib.SetTheory.Cardinal.Finite
    26import Lax366625.CountingProblems
    27
    28/-!
    29---
    30title: Counting knapsack and 0-1 integer programming solutions
    31type: definition
    32---
    33The weights are written in binary as in the NP catalog. #Knapsack counts the
    34sets of items whose total weight is exactly the target, and #0-1 Integer
    35Programming counts the 00-11 vectors satisfying every constraint of the
    36system with equality.
    37-/
    38
    39namespace Lax280166.CountingKnapsacks
    40
    41open Lax799700.Knapsack Lax799700.ZeroOneIP Lax904597.Machines
    42
    43open FirstOrder
    44
    45open Language Structure
    46
    47section Solutions
    48
    49variable (A : Type) [binWeights.Structure A]
    50
    51/-- The set `S` of items is a solution: the instance is finite, its order is
    52linear, and the weights of `S` sum exactly to the target. -/
    53def KnapsackSol (S : A → Prop) : Prop :=
    54 Finite A ∧ IsLinOrd (BWLe (A := A)) ∧ (∀ i, S i → BWItem i) ∧
    55 (∑ᶠ i ∈ {i | S i}, BWWeight i) = BWTarget A
    56
    57open FirstOrder
    58
    59open Language Structure
    60
    61variable (A : Type) [zeroOneIP.Structure A]
    62
    63/-- The set `x` of columns is a solution: the instance is finite, its order is
    64linear, and every equation holds. -/
    65def ZeroOneSol (x : A → Prop) : Prop :=
    66 Finite A ∧ IsLinOrd (IPLe (A := A)) ∧ (∀ j, x j → IPCol j) ∧
    67 ∀ r, IPRow r → (∑ᶠ j ∈ {j | x j}, IPCoefVal r j) = IPRhsVal r
    68
    69end Solutions
    70
    71open Lax366625.CountingProblems
    72
    73/-- **#Knapsack**, as a counting problem. -/
    74noncomputable def SharpKnapsack : CountingProblem Lax799700.Knapsack.binWeights :=
    75 CountingProblem.ofFun fun A _ =>
    76 Nat.card {S : A → Prop // KnapsackSol A S}
    77
    78/-- **#0-1 Integer Programming**, as a counting problem. -/
    79noncomputable def SharpZeroOneIP : CountingProblem Lax799700.ZeroOneIP.zeroOneIP :=
    80 CountingProblem.ofFun fun A _ =>
    81 Nat.card {x : A → Prop // ZeroOneSol A x}
    82
    83end Lax280166.CountingKnapsacks
    84

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…