@@ -6315,6 +6315,7 @@ theorem two_pow_ctz_le_toNat_of_ne_zero {x : BitVec w} (hx : x ≠ 0#w) :
63156315theorem cpopNatRec_zero_eq_self {x : BitVec w} :
63166316 x.cpopNatRec 0 acc = acc := rfl
63176317
6318+ @[simp]
63186319theorem cpopNatRec_succ {n : Nat} {x : BitVec w} :
63196320 x.cpopNatRec (n + 1 ) acc = x.cpopNatRec n (acc + (x.getLsbD n).toNat) := rfl
63206321
@@ -6326,26 +6327,17 @@ theorem cpopNatRec_zero :
63266327 · case succ n ihn =>
63276328 simp [cpopNatRec_succ, ihn]
63286329
6329- @[simp]
63306330theorem add_cpopNatRec_zero {x : BitVec w} {acc n : Nat} :
6331- x.cpopNatRec n 0 + acc = x.cpopNatRec n acc := by
6331+ x.cpopNatRec n acc = x.cpopNatRec n 0 + acc := by
63326332 induction n generalizing acc
63336333 · simp
63346334 · case _ n ihn =>
6335- simp only [cpopNatRec_succ]
6336- rw [← ihn, ← @ihn (acc + (x.getLsbD n).toNat)]
6335+ simp [cpopNatRec_succ, ihn (acc := acc + (x.getLsbD n).toNat), ihn (acc := (x.getLsbD n).toNat)]
63376336 omega
63386337
6339- @[simp]
6340- theorem cpopNatRec_zero_add {x : BitVec w} {acc n : Nat} :
6341- acc + x.cpopNatRec n 0 = x.cpopNatRec n acc := by
6342- rw [Nat.add_comm]
6343- simp
6344-
63456338theorem cpopNatRec_add_eq_add_cpopNatRec {x : BitVec w} {acc n : Nat} :
63466339 x.cpopNatRec n (acc + acc') = x.cpopNatRec n acc + acc' := by
6347- rw [← add_cpopNatRec_zero (acc := acc + acc'), ← add_cpopNatRec_zero (acc := acc)]
6348- omega
6340+ rw [add_cpopNatRec_zero (acc := acc + acc'), add_cpopNatRec_zero (acc := acc), Nat.add_assoc]
63496341
63506342theorem cpopNatRec_le {x : BitVec w} (n : Nat) :
63516343 x.cpopNatRec n acc ≤ acc + n := by
@@ -6409,7 +6401,7 @@ theorem toNat_cpop_le (x : BitVec w) :
64096401 exact hle
64106402
64116403@[simp]
6412- theorem cpopNatRec_cons_eq_cpopNatRec_of_le {x : BitVec w} {b : Bool} (hn : n ≤ w) :
6404+ theorem cpopNatRec_cons_of_le {x : BitVec w} {b : Bool} (hn : n ≤ w) :
64136405 (cons b x).cpopNatRec n acc = x.cpopNatRec n acc := by
64146406 induction n generalizing acc
64156407 · simp
@@ -6418,7 +6410,19 @@ theorem cpopNatRec_cons_eq_cpopNatRec_of_le {x : BitVec w} {b : Bool} (hn : n
64186410 rw [cpopNatRec_succ, ihn, getLsbD_cons]
64196411 simp [show ¬ n = w by omega, cpopNatRec_succ]
64206412
6421- theorem cpopNatRec_concat_eq_add_cpopNatRec_of_lt {x : BitVec w} {b : Bool} (hn : 0 < n) :
6413+ @[simp]
6414+ theorem cpopNatRec_cons_of_lt {x : BitVec w} {b : Bool} (hn : w < n) :
6415+ (cons b x).cpopNatRec n acc = b.toNat + x.cpopNatRec n acc := by
6416+ induction n generalizing acc
6417+ · omega
6418+ · case _ n ihn =>
6419+ by_cases hlt : w < n
6420+ · rw [cpopNatRec_succ, ihn (acc := acc + ((cons b x).getLsbD n).toNat) (by omega)]
6421+ simp [getLsbD_cons, show ¬ n = w by omega]
6422+ · simp [show w = n by omega, getElem_cons,
6423+ cpopNatRec_add_eq_add_cpopNatRec (acc := acc) (acc' := b.toNat), Nat.add_comm]
6424+
6425+ theorem cpopNatRec_concat_of_lt {x : BitVec w} {b : Bool} (hn : 0 < n) :
64226426 (concat x b).cpopNatRec n acc = b.toNat + x.cpopNatRec (n - 1 ) acc := by
64236427 induction n generalizing acc
64246428 · omega
@@ -6442,7 +6446,7 @@ theorem toNat_cpop (x : BitVec w) :
64426446@[simp]
64436447theorem toNat_cpop_cons {x : BitVec w} {b : Bool} :
64446448 (x.cons b).cpop.toNat = b.toNat + x.cpop.toNat := by
6445- simp [toNat_cpop, cpopNatRec_succ, getElem_cons ]
6449+ simp [toNat_cpop, getElem_cons, add_cpopNatRec_zero (acc := b.toNat), Nat.add_comm ]
64466450
64476451@[simp]
64486452theorem cpopNatRec_setWidth_eq_of_le (x : BitVec w) (h : pos ≤ v) :
0 commit comments