Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: List.SatisfiesM_foldlM #1034

Merged
merged 4 commits into from
Nov 12, 2024
Merged

feat: List.SatisfiesM_foldlM #1034

merged 4 commits into from
Nov 12, 2024

Conversation

kim-em
Copy link
Collaborator

@kim-em kim-em commented Nov 11, 2024

No description provided.

@github-actions github-actions bot added the WIP work in progress label Nov 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 11, 2024
@kim-em kim-em marked this pull request as ready for review November 11, 2024 02:30
@kim-em
Copy link
Collaborator Author

kim-em commented Nov 11, 2024

In conjunction with #1029, and leanprover/lean4#6023, we can do things like:

def addRandomEvens (n : Nat) (k : Nat) : IO Nat := do
  let mut r := k
  for _ in List.range n do
    r := r + 2 * (← IO.rand 0 37)
  pure r

theorem addRandomEvens_spec (n k) : SatisfiesM (fun r => r % 2 = k % 2) (addRandomEvens n k) := by
  rw [addRandomEvens]
  simp [List.forIn_yield_eq_foldlM]
  apply List.SatisfiesM_foldlM
  · rfl
  · intros b w a m
    apply SatisfiesM.bind_pre
    simp_all [SatisfiesM_EStateM_eq, EStateM.run]

def addRandomEvens' (n : Nat) (k : Nat) : IO { r : Nat // r % 2 = k % 2 } := do
  satisfying (addRandomEvens_spec n k)

@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Nov 11, 2024

Mathlib CI status (docs):

@kim-em kim-em removed the WIP work in progress label Nov 12, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 12, 2024
Co-authored-by: Eric Wieser <[email protected]>
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 12, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 12, 2024
@fgdorais fgdorais added this pull request to the merge queue Nov 12, 2024
Merged via the queue into main with commit 66a3bd2 Nov 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants