Skip to content

Conversation

@Eduardogbg
Copy link
Collaborator

  • also some misc stuff about trivial/exact () being redundant due to a tactics change that I had in a different commit but now I squashed oops
  • not sure where to put some of these lemmas, also not sure if there's any formatting rules etc I need to follow
  • should I document some of these lemmas/theorems?

@Eduardogbg Eduardogbg requested a review from kustosz December 15, 2025 19:28
@Eduardogbg
Copy link
Collaborator Author

also I think I named lemmas vs theorems pretty arbitrarily, it appears the codebase convention is to just use theorem?

conv_rhs => rw [RadixVec.msd_lsds_decomposition (v:=n)]
have := Fin.val_eq_of_eq $ ih (n := n.lsds)
simpa [RadixVec.ofDigitsBE, RadixVec.toDigitsBE, RadixVec.ofLimbsBE]
theorem RadixVec.toDigitsBE'_bytes_eq_map_toFin_map_ofNatLT (hr : 1 < 256) (m : ℕ) :
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so I didn't know if I should move this one to Helpers cuz it depends on a specific base? maybe I should abstract it right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would dispute this being a theorem worth stating at all, why do we need it? It's only used once

simp_all
· simp_all

theorem List.take_succ_lt_of_take_lt [DecidableEq α] [LT α] [DecidableLT α] {l₁ l₂ : List α}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't know where to put all these list/bitvec lemmas

Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, some new file I guess, in a subtree that suggests "mathlib extensions go here"

theorem ofDigitsBE'_toList {r : Radix} {l : List.Vector (Digit r) d}: RadixVec.ofDigitsBE' l.toList = (RadixVec.ofDigitsBE l).val := by
simp only [RadixVec.ofDigitsBE']
congr <;> simp
theorem ofDigitsBE'_lt_of_shorter_than_modulus {r : Radix} {data : List (Digit r)} {P : Prime}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also wasn't sure if I should move this to RadixVec cuz it depends on Prime and stuff...

Copy link
Contributor

@kustosz kustosz left a comment

Choose a reason for hiding this comment

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

Good stuff! Please try to bring formatting closer to https://leanprover-community.github.io/contribute/style.html

simp_all
· simp_all

theorem List.take_succ_lt_of_take_lt [DecidableEq α] [LT α] [DecidableLT α] {l₁ l₂ : List α}
Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, some new file I guess, in a subtree that suggests "mathlib extensions go here"

_ < (r - 1) * r.val ^ d + r.val ^ d := by simp [*]
_ = (↑r - 1) * ↑r ^ d + 1 * ↑r ^ d := by simp
_ = _ := by rw [←Nat.add_mul, this, mul_comm]
theorem List.Vector.map_toFin_map_ofFin {n d : ℕ} (v : List.Vector (Fin (2^n)) d) :
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of this theorem existing at all. It's a combination of just List.Vector.map_map and List.Vector.map_id, no need to be so specific about the functions involved. I'd buy just toFin_ofFin : _ = id used in conjunction with the above, but this level of specialization here feels excessive

apply List.Vector.eq
simp only [List.Vector.toList_map, List.map_map, BitVec.toFin_ofFin_comp, List.map_id]

theorem List.Vector.map_ofFin_map_toFin {n d : ℕ} (v : List.Vector (BitVec n) d) :
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

theorem List.Vector.reverse_map {α β : Type} {d : ℕ} (v : List.Vector α d) (f : α → β) :
(v.map f).reverse = v.reverse.map f := by
apply List.Vector.eq
simp only [List.Vector.toList_reverse, List.Vector.toList_map, List.map_reverse]
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just simp?

conv_rhs => rw [RadixVec.msd_lsds_decomposition (v:=n)]
have := Fin.val_eq_of_eq $ ih (n := n.lsds)
simpa [RadixVec.ofDigitsBE, RadixVec.toDigitsBE, RadixVec.ofLimbsBE]
theorem RadixVec.toDigitsBE'_bytes_eq_map_toFin_map_ofNatLT (hr : 1 < 256) (m : ℕ) :
Copy link
Contributor

Choose a reason for hiding this comment

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

I would dispute this being a theorem worth stating at all, why do we need it? It's only used once

@iamrecursion iamrecursion changed the title verify big-endian and little-endian radix/bits/bytes Verify big-endian and little-endian radix/bits/bytes Jan 7, 2026
@iamrecursion iamrecursion added the enhancement New feature or request label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants