Skip to content

feat(Algorithms): add verified binary search with O(log n) time proof#443

Open
zacn04 wants to merge 1 commit intoleanprover:mainfrom
zacn04:feat/binary-search
Open

feat(Algorithms): add verified binary search with O(log n) time proof#443
zacn04 wants to merge 1 commit intoleanprover:mainfrom
zacn04:feat/binary-search

Conversation

@zacn04
Copy link

@zacn04 zacn04 commented Mar 19, 2026

Summary

  • Add binarySearch on sorted arrays using the TimeM ℕ monad to count comparisons
  • Prove correctness: binarySearch_found (result implies arr[mid] = target) and binarySearch_not_found (absence on sorted array)
  • Prove time complexity: at most ⌈log₂(n + 1)⌉ comparisons (binarySearch_time)
  • All proofs are sorry-free
  • Follows MergeSort conventions: module, @[expose] public section, Cslib.Algorithms.Lean.TimeM namespace

Test plan

  • lake build --wfail --iofail passes
  • lake exe mk_all --module (Cslib.lean updated)
  • lake exe lint-style passes
  • lake test (CI)
  • lake lint (CI)

🤖 Generated with Claude Code

Add binary search on sorted arrays using the TimeM monad to count
comparisons. Proves correctness (found implies arr[mid] = target,
not found on sorted array implies target absent) and time complexity
(at most ⌈log₂(n+1)⌉ comparisons), all without sorry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Shreyas4991
Copy link
Contributor

Duplicate of #237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants