lean4-htt/src/Std
Sebastian Graf ae8dc414c3
feat: mvcgen invariants? to scaffold initial invariants (#10456)
This PR implements `mvcgen invariants?` for providing initial invariant
skeletons for the user to flesh out. When the loop body has an early
return, it will helpfully suggest `Invariant.withEarlyReturn ...` as a
skeleton.

```lean
def mySum (l : List Nat) : Nat := Id.run do
  let mut acc := 0
  for x in l do
    acc := acc + x
  return acc

/--
info: Try this:
  invariants
    · ⇓⟨xs, acc⟩ => _
-/
#guard_msgs (info) in
theorem mySum_suggest_invariant (l : List Nat) : mySum l = l.sum := by
  generalize h : mySum l = r
  apply Id.of_wp_run_eq h
  mvcgen invariants?
  all_goals admit

def nodup (l : List Int) : Bool := Id.run do
  let mut seen : HashSet Int := ∅
  for x in l do
    if x ∈ seen then
      return false
    seen := seen.insert x
  return true

/--
info: Try this:
  invariants
    · Invariant.withEarlyReturn (onReturn := fun r acc => _) (onContinue := fun xs acc => _)
-/
#guard_msgs (info) in
theorem nodup_suggest_invariant (l : List Int) : nodup l ↔ l.Nodup := by
  generalize h : nodup l = r
  apply Id.of_wp_run_eq h
  mvcgen invariants?
  all_goals admit
```
2025-09-19 14:05:24 +00:00
..
Data feat: overhaul meta system (#10362) 2025-09-17 21:04:29 +00:00
Do feat: mvcgen invariants? to scaffold initial invariants (#10456) 2025-09-19 14:05:24 +00:00
Internal feat: add signal handling support using libuv (#9258) 2025-09-15 13:09:50 +00:00
Net refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Sat fix: make rw collect only new goals, occurs check (#10306) 2025-09-14 04:44:55 +00:00
Sync fix: check that compiler does not infer inconsistent types between modules (#10418) 2025-09-19 12:36:47 +00:00
Tactic feat: mvcgen invariants? to scaffold initial invariants (#10456) 2025-09-19 14:05:24 +00:00
Time fix: check that compiler does not infer inconsistent types between modules (#10418) 2025-09-19 12:36:47 +00:00
Data.lean feat: add useful functions in Parsec, add error variant and Std.Data.ByteSlice (#9599) 2025-09-11 14:53:41 +00:00
Do.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Internal.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Net.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Sat.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Sync.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Tactic.lean refactor: module-ize remainder of Std (#9195) 2025-07-17 11:43:57 +00:00
Time.lean refactor: module-ize Std.Time (#9100) 2025-07-16 09:57:53 +00:00