lean4-htt/src
Henrik Böving 20571a938b
feat: bv_decide support for simple pattern matching on enum inductives (#7329)
This PR adds support to bv_decide for simple pattern matching on enum
inductives. By simple we mean non dependent match statements with all
arms written out.

This PR enables use cases such as:
```lean
namespace PingPong

inductive Direction where
  | goingDown
  | goingUp

structure State where
  val : BitVec 16
  low : BitVec 16
  high : BitVec 16
  direction : Direction

def State.step (s : State) : State :=
  match s.direction with
  | .goingDown =>
    if s.val = s.low then
      { s with direction := .goingUp }
    else
      { s with val := s.val - 1 }
  | .goingUp =>
    if s.val = s.high then
      { s with direction := .goingDown }
    else
      { s with val := s.val + 1 }

def State.steps (s : State) (n : Nat) : State :=
  match n with
  | 0 => s
  | n + 1 => (State.steps s n).step

def Inv (s : State) : Prop := s.low ≤ s.val ∧ s.val ≤ s.high ∧ s.low < s.high

example (s : State) (h : Inv s) (n : Nat) : Inv (State.steps s n) := by
  induction n with
  | zero => simp only [State.steps, Inv] at *; bv_decide
  | succ n ih =>
    simp only [State.steps, State.step, Inv] at *
    bv_decide
```

There is an important thing to consider in this implementation. As the
enums pass can now deal with control flow there is a tension between the
structures and enums pass at play:
1. Enums should run before structures as it could convert matches on
enums into `cond`
chains. This in turn can be used by the structures pass to float
projections into control
   flow which might be necessary.
2. Structures should run before enums as it could reveal new facts about
enums that we might
need to handle. For example a structure might contain a field that
contains a fact about
   some enum. This fact needs to be processed properly by the enums pass

To resolve this tension we do the following:
1. Run the structures pass (if enabled)
2. Run the enums pass (if enabled)
3. Within the enums pass we rerun the part of the structures pass (if
enabled) that could profit from the
enums pass as described above. This comes down to adding a few more
lemmas to a simp
invocation that is going to happen in the enums pass anyway and should
thus be cheap.
2025-03-07 09:23:48 +00:00
..
bin feat: API to avoid deadlocks from dropped promises (#6958) 2025-02-07 15:33:10 +00:00
cmake fix: Windows stage0 linking (#6622) 2025-01-14 09:09:50 +01:00
include/lean feat: IntX.abs (#7131) 2025-02-18 13:16:30 +00:00
Init feat: combine two cutsat proof steps (#7371) 2025-03-06 23:28:49 +00:00
initialize
kernel perf: optimize sorry detection in unused variables linter (#7129) 2025-02-22 16:43:39 +00:00
lake feat: debug_assert! (#7256) 2025-03-03 16:34:44 +00:00
Lean feat: bv_decide support for simple pattern matching on enum inductives (#7329) 2025-03-07 09:23:48 +00:00
library chore: reimplement mk_projections in Lean (#7295) 2025-03-03 01:10:27 +00:00
runtime perf: use free_sized in mpz.cpp (#6825) 2025-03-03 08:47:15 +00:00
shell chore: avoid rebuilding leanmanifest in each build (#5057) 2024-08-15 14:55:36 +00:00
Std feat: tree map lemmas for ofList (#7360) 2025-03-06 16:20:52 +00:00
util fix: set CP_UTF8 on Windows (#7213) 2025-02-26 18:36:32 +00:00
cadical.mk feat: ship cadical (#4325) 2024-08-23 09:13:27 +00:00
CMakeLists.txt chore: begin development cycle for v4.19.0 (#7299) 2025-03-03 11:01:21 +00:00
config.h.in
githash.h.in
Init.lean feat: binderNameHint (#6947) 2025-02-06 11:03:27 +00:00
lakefile.toml.in feat: Lake plugin w/ USE_LAKE (#7233) 2025-02-26 04:05:15 +00:00
lean-toolchain
Lean.lean feat: use realizeConst for all equation, unfold, induction, and partial fixpoint theorems (#7261) 2025-03-06 15:38:04 +00:00
lean.mk.in feat: use realizeConst for all equation and unfold theorems (#7348) 2025-03-05 14:56:50 +00:00
Leanc.lean
Std.lean feat: Std.Net.Addr (#6563) 2025-01-09 09:33:03 +00:00
stdlib.make.in fix: make the stage2 Leanc build use stage2 oleans rather than stage1 oleans (#7190) 2025-02-25 06:20:50 +00:00
stdlib_flags.h feat: add debug.proofAsSorry (#6300) 2024-12-03 23:21:38 +00:00
version.h.in chore: tag prerelease builds with -pre (#5943) 2024-11-06 14:47:52 +00:00