Skip to content

Upstreaming bit, div2, bodd and establishing binary recursion.#1737

Open
linesthatinterlace wants to merge 17 commits intoleanprover-community:mainfrom
linesthatinterlace:binary_rewrite
Open

Upstreaming bit, div2, bodd and establishing binary recursion.#1737
linesthatinterlace wants to merge 17 commits intoleanprover-community:mainfrom
linesthatinterlace:binary_rewrite

Conversation

@linesthatinterlace
Copy link
Copy Markdown
Contributor

This PR aims to produce a cleanly structured characterisation of bodd, div2 and bit, and use them to define a form of binary induction that is clean and easy to work with.

@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Mar 26, 2026
linesthatinterlace and others added 3 commits March 26, 2026 16:50
Add bit arithmetic lemmas (bit_false, bit_true, bit_add, bit_add_bit),
complete the leastBits/ofLeastBits section with simp lemmas, inverse
proofs, injectivity, and the connection between bits and leastBits
via bits_eq_leastBits_elim. Remove grind attributes from bodd_val,
div2_val, bit_val to prevent grind from escaping into arithmetic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename bits → bitsList, ofBits → ofBitsList, leastBits → leastBitsList,
ofLeastBits → ofLeastBitsList to avoid clashes with existing Nat.ofBits.
Add testBit lemmas for bitsList/ofBitsList, getElem_bitsList,
bitsList_eq_ofFn_testBit. Sketch toBitVec, toLeastBitVec, ofBitVec,
ofLeastBitVec definitions. Remove grind attributes from _val lemmas.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change binaryElim's bit callback from Nat → α → α to Bool → α → α,
since only n.bodd is ever used. This simplifies all binaryElim-based
definitions. Add binaryElim_bit/binaryElim_bit_apply showing
binaryElim 0 1 bit = id. Remove BitVec sketches for now. Tidy
docstrings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@AlexeyMilovanov AlexeyMilovanov left a comment

Choose a reason for hiding this comment

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

The CI is currently failing, but I verified locally that these suggestions fix it. I think it's just the strict simpNF linter catching these 6 lemmas. With @[simp] removed here, both lake build and lake lint pass perfectly

mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 30, 2026
@fgdorais
Copy link
Copy Markdown
Collaborator

fgdorais commented Apr 1, 2026

I think we could use this opportunity to change bodd to isOdd. Maybe also add isEven (perhaps just as an abbrev for !isOdd).

mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Apr 1, 2026
@linesthatinterlace
Copy link
Copy Markdown
Contributor Author

I would be fine with changing bodd to isOdd and added isEven. Personally I would define it separately and then have !isEven = isOdd as a theorem but ultimately it's to taste.

@linesthatinterlace
Copy link
Copy Markdown
Contributor Author

(I note by the way that we don't have the following inductive definitions. I am not proposing to add them and it isn't clear they would be suitable in batteries! However, I could certainly imagine Nat.Odd and Nat.Even existing.)


inductive Odd : Nat → Prop
  | one : Odd 1
  | add_two : Odd n → Odd (n + 2)

inductive Even : Nat → Prop
  | zero : Even 0
  | add_two : Even n → Even (n + 2)

mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Apr 1, 2026
mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Apr 1, 2026
mathlib-nightly-testing bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review This PR is ready for review; the author thinks it is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants