Skip to content

feat(InformationTheory/Coding): add Kraft inequality for prefix-free codes - #42584

Open
elazarg wants to merge 6 commits into
leanprover-community:masterfrom
elazarg:feat/prefix-free-kraft
Open

feat(InformationTheory/Coding): add Kraft inequality for prefix-free codes#42584
elazarg wants to merge 6 commits into
leanprover-community:masterfrom
elazarg:feat/prefix-free-kraft

Conversation

@elazarg

@elazarg elazarg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This PR defines prefix-free codes and, over a finite, nonempty alphabet, proves Kraft's inequality for finite and arbitrary prefix-free codes. It is a direct continuation of #34108, which introduced uniquely decodable codes and the Kraft–McMillan inequality.

The results live in the InformationTheory namespace under InformationTheory/Coding.

Main definitions

  • InformationTheory.PrefixFree: a set of codewords is prefix-free if two codewords in the set cannot be distinct when one is a prefix of the other.

Main results

  • InformationTheory.PrefixFree.uniquelyDecodable: a prefix-free code not containing the empty word is uniquely decodable.
  • InformationTheory.PrefixFree.uniquelyDecodable_of_nontrivial: every nontrivial prefix-free code is uniquely decodable.
  • InformationTheory.kraft_inequality: the Kraft sum of a finite prefix-free code is at most one.
  • InformationTheory.summable_kraft_sum: the Kraft series of an arbitrary prefix-free code is summable.
  • InformationTheory.kraft_inequality_infinite: the Kraft sum of an arbitrary prefix-free code is at most one.

This is another part of https://github.com/elazarg/kraft. Comments about next items are welcome.

Open in Gitpod

@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions github-actions Bot added the t-measure-probability Measure theory / Probability theory label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

PR summary fd95666751

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.InformationTheory.Coding.PrefixFree (new file) 195
Mathlib.InformationTheory.Coding.Kraft (new file) 1603

Declarations diff (regex)

+ PrefixFree
+ PrefixFree.eq_singleton_empty_of_empty_mem
+ PrefixFree.mono
+ PrefixFree.uniquelyDecodable
+ PrefixFree.uniquelyDecodable_of_nontrivial
+ kraft_inequality
+ kraft_inequality_infinite
+ sum_kraft_le_one
+ summable_kraft_sum

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

Lean-aware diff — post-build, computed from the Lean environment (commit fd95666).

  • +8 new declarations
  • −0 removed declarations
+InformationTheory.PrefixFree
+InformationTheory.PrefixFree.eq_singleton_empty_of_empty_mem
+InformationTheory.PrefixFree.mono
+InformationTheory.PrefixFree.uniquelyDecodable
+InformationTheory.PrefixFree.uniquelyDecodable_of_nontrivial
+InformationTheory.kraft_inequality
+InformationTheory.kraft_inequality_infinite
+InformationTheory.summable_kraft_sum

No changes to strong technical debt.

Increase in weak tech debt: (relative, absolute) = (2.00, 0.00)
Current number Change Type (weak)
5051 2 exposed public sections

Current commit fd95666751
Reference commit 639923353f

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

Comment thread Mathlib/InformationTheory/Coding/Kraft.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
elazarg and others added 2 commits August 9, 2026 11:27
Co-authored-by: Weiyi Wang <wwylele@gmail.com>
@elazarg
elazarg requested a review from wwylele August 9, 2026 10:18

@wwylele wwylele left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me

Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Comment thread Mathlib/InformationTheory/Coding/Kraft.lean Outdated
@elazarg
elazarg requested a review from wwylele August 9, 2026 15:57
Comment thread Mathlib/InformationTheory/Coding/PrefixFree.lean Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-measure-probability Measure theory / Probability theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants